Is there a way to export a range of data of my current worksheet to the next blank row on a closed workbook? I have a template excel file used to place orders and I want to copy the order information (ex B3:F3) to the next available row in a workbook that has all of the orders.
Thanks
Under certain circumstances, yes. You can use ADO to export data from the activeworkbook to a sheet in a closed workbook as long as that destination workbook has headers, and as long as you include a header row in the source that you export from. For example:
Note that there is a memory leak issue with using ADO on an open workbook, but as long as you only run one or two exports at a time (and then close Excel) it shouldn't be a problem.Sub ExportDataFromThisWorkbookToClosedWorkbook() ' Sample demonstrating how to export data from the current workbook to a closed workbook Dim cn As Object, strQuery As String Set cn = CreateObject("ADODB.Connection") With cn .Provider = "Microsoft.Jet.OLEDB.4.0" .ConnectionString = "Data Source=" & ActiveWorkbook.FullName & ";" & _ "Extended Properties=""Excel 8.0;HDR=Yes;""" .Open End With strQuery = "INSERT INTO [Sheet1$] IN '' [Excel 8.0;Database=C:\ADO Dest.xls] SELECT * FROM [Sheet1$B2:F3]" cn.Execute strQuery cn.Close Set cn = Nothing End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks