
Originally Posted by
PeterT
If you write your data to a temporary table in access then run the command TransferSpreadsheet to send it to excel.
Then use the Excel file name and Data sheet name from the TransferSpreadsheet command to call this little function.
The function opens an excel object for your named spreadsheet, selects row 1 and deletes it; then saves and closes the spreadsheet.
Example Sub nnnn
Dim etc.
exFileName = "T:\Data148.xls"
myTempTableName = "tmp_myData"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, myTempTableName, exFileName
Call RemoveFirstRowExcel(exFileName, myTempTableName )
End Sub
Called Function as follows
Public Sub RemoveFirstRowExcel(SSFile As String, SSSheet As String)
On Error GoTo Exit_Proc
Dim xlApp As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(SSFile).Sheets(1)
With xlApp
.Application.Sheets(SSSheet).Select
.Application.Rows("1:1").Select
.Application.Selection.EntireRow.Delete
.Application.Activeworkbook.Save
.Application.Activeworkbook.Close
.Quit
End With
Exit_Proc:
Set xlApp = Nothing
Set xlSheet = Nothing
End Sub
I use this in Access 2003 but I see no reason why it should not work in Access 2007 (or 2010)
PeterT.
Can you assist me?
I am modifying an Access 2007 database as a volunteer for a charitable organization, and I need to automate export of Access Query data to an existing Excel 2007 work-sheet.
So far, I have got to the stage where this happens, but I need to have the column headings left-out.
Here is the code that works, but it brings-in the column headings which I don't want.
Code:
'------------------------------------------------------------
' Command104ContrDonatWeekly_Click
'
'------------------------------------------------------------
Private Sub Command104ContrDonatWeekly_Click()
On Error GoTo Command104ContrDonatWeekly_Click_Err
DoCmd.OpenQuery "Contributors Who Donated in Past Week", acViewNormal, acEdit
XLFile = "C:\Users\Michael1\Desktop\KSN\DistributionListWeekly.xlsb"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, _
"Contributors Who Donated in Past Week", XLFile, True, "Sheet2"
FollowHyperlink XLFile
Command104ContrDonatWeekly_Click_Exit:
Exit Sub
Command104ContrDonatWeekly_Click_Err:
MsgBox Error$
Resume Command104ContrDonatWeekly_Click_Exit
End Sub
Can you show me precisely where your code would meld with the one I am using (I am lost when you say "Example Sub nnnn
Dim etc." & not sure if "Called Function as follows" is a part of the code or your passing comment.
Cheers.
MichaelN