Yes, a single button Click event could execute all code.
Why even need Excel component? What is method of import - can't just link to the Excel?
VBA can certainly do whatever the macro does, and more.
Here is one users solution for the export http://social.msdn.microsoft.com/For...3-a891fe1ae43b.
Alternative to TransferSpreadsheet would be opening the existing workbook as an Excel object in VBA that could be manipulated. I modified code from the following and it almost totally works. Unfortunately an instance of Excel persists in Task Manager processes. Something about the Add worksheet line that is not right.
http://social.msdn.microsoft.com/For...8-5617865b1e82
http://www.mrexcel.com/archive/VBA/1869.html
http://www.exceltip.com/st/Close_a_w...Excel/469.html
Solution to the Add sheet code found at http://www.vbforums.com/showthread.p...xisting-sheets
Can't get new sheet to add to end of sheets.
Will need VBA reference to Microsoft Excel 12.0 Object Library.
Code:
Private Sub SaveRecordsetToExcelRange()
' Excel Objects:
Dim objXL As Excel.Application
Dim objWBK As Excel.Workbook
Dim objRS As DAO.Recordset
' Open a DAO recordset on the query:
Set objRS = CurrentDb.OpenRecordset("SELECT * FROM table1;")
' Open Excel and point to the cell where the recordset is to be inserted:
Set objXL = New Excel.Application
objXL.Visible = True
Set objWBK = objXL.Workbooks.Open("C:\Temp\Test.xlsx")
objWBK.Worksheets.Add().Name = "Test"
objWBK.Worksheets("Test").Range("A1").CopyFromRecordset objRS
objWBK.Close True
objXL.Quit
' Destroy objects:
Set objWBK = Nothing
Set objXL = Nothing
If Not objRS Is Nothing Then
objRS.Close
Set objRS = Nothing
End If
End Sub