VBA Code to Export an Access Query to Excel without the Header Row
I am trying to export an Access query to Excel, but I would like to exclude the header row from being exported. I am using the TransferSpreadsheet command below in VBA and I have the "has field names" option set to False, but the command is still exporting the header row to my Excel spread.
Does anyone know how to accomplish this using the TransferSpreadsheet command or is there another line of code that can accomplish this? I've read from several sources that there might be a way to run the TransferSpreadsheet command first and then in the next line of code open the Excel spreadsheet and send a command to delete the first row with the header information. However, no one has been able to provided the code to do such an action.
From VBA Help on the TransferSpreadsheet method
Use True (–1) to use the first row of the spreadsheet as field names when importing or linking. Use False (0) to treat the first row of the spreadsheet as normal data. If you leave this argument blank, the default (False) is assumed. When you export Access table or select query data to a spreadsheet, the field names are inserted into the first row of the spreadsheet no matter what you enter for this argument.
Options include doing as you mention to delete the first row in the spreadsheet or creating the spreadsheet using Excel automation instead of using the TransferSpreadsheet method.
OM Gang
Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.
Actaully don't need the
wb.Close savechanges:=False
In the Exit statement. Left over from the module I started with.
OM Gang
0
mjstuparichAuthor Commented:
OM Gang,
Thanks for the clarificaiton on the True/False options using the TransferSpreadsheet method. Do you have any examples of the Excel automation method that you can share with me? To answer your question I am outputting 26 fields to my Excel spreadsheet.
See if what I've posted works for you. If not, I can also supply a sample function to create the Excel workbook, without header row, using automation.
OM Gang
I guess I should have added
to use the function to delete the first row from the newly created spreadsheet you can call it from your existing procedure that is using the TransferSpreadsheet method. Modify my sample function to accept the file path/name as an input parameter
Public Function DeleteRowInExcel(MyFileName As String)
On Error GoTo Err_DeleteRowInExcel
Dim xlApp As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.
Use True (–1) to use the first row of the spreadsheet as field names when importing or linking. Use False (0) to treat the first row of the spreadsheet as normal data. If you leave this argument blank, the default (False) is assumed. When you export Access table or select query data to a spreadsheet, the field names are inserted into the first row of the spreadsheet no matter what you enter for this argument.
Options include doing as you mention to delete the first row in the spreadsheet or creating the spreadsheet using Excel automation instead of using the TransferSpreadsheet method.
OM Gang