Rehash Unesolved Question Exporting Access to Excel

Wapug

Registered User.
Local time
Yesterday, 19:12
Joined
Apr 14, 2017
Messages
51
I have 3 access queries all of which I would like to export to an excel spreadsheet that has three sheets named for the queries. The VBA I have written exports the data out to the correct sheets, but I would like to add code that will delete the existing data on the three sheets before adding the new data from my queries. Please help. Is there something simple Im missing or is this a more complicated problem?
Private Sub Command0_Click()
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Query1", "C:\Users\bacon\Desktop\test1.xlsx"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Query2", "C:\Users\bacon\Desktop\test1.xlsx"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Query3", "C:\Users\bacon\Desktop\test1.xlsx"
End Sub
 
If you are willing to open an Excel Application Object, you can

1. Open the workbook file
2. Delete the sheets
3. Create them again, but empty.
4. Save and Close the Workbook.
5. Do your export

It WOULD be possible to delete the cells, but the truth is that a wholesale "delete whole sheet" is a LOT easier.
 
Im open o anything so long as my data ends up in the workbook. Could you advise how I could do this or point me in the right direction?
 
Internet search for "access vba excel automation"

Automation will enable you to do the things outlined by Doc.

@Doc, "LOT easier" is of course dependent on whether the worksheet has specialized formatting.
 
True enough, Cronk, but from the description in post #1, isn't the TransferSpreadSheet with Export option going to give you vanilla spreadsheets anyway?

In any case, Wapug, it is possible for you to write code that would do piecemeal deletion of cell contents, but I'll ask the direct question. Is special formatting involved in the exported spreadsheets? If not, then wholesale sheet deletion is easier.
 

Users who are viewing this thread

Back
Top Bottom