I am using the following code to output a report into Excel 2003 in order to achieve the following:
1 Output RptSignatureSheet to Excel
2 Save it as an excel file (signaturedata.xls).
3 Open file (Trophy Sig Sheet.xls) which has links to signaturedata.xls.
4 Update the links and close signaturedata.xls
5 Save Trophy Sig Sheet.xls
6 Return to Access, leaving Excel running with Trophy Sig Sheet open
The Excel Macro looks like this:
This works well but leaves me with two workbooks open - Trophy Sig Sheet and ExcelMacros. I have tried various ways to get the ExcelMacros workbook to close but each time I end up with an Access error message.
Can anyone please advise how I can modify either the Access or Excel codes to get the ExcelMacros workbook to close and leave just the Trophy Sig Sheet workbook open.
Thanks a lot
John
1 Output RptSignatureSheet to Excel
2 Save it as an excel file (signaturedata.xls).
3 Open file (Trophy Sig Sheet.xls) which has links to signaturedata.xls.
4 Update the links and close signaturedata.xls
5 Save Trophy Sig Sheet.xls
6 Return to Access, leaving Excel running with Trophy Sig Sheet open
Code:
Dim oXL As Object, x
stDocName = "RptSignatureSheet"
Set oXL = CreateObject("Excel.Application")
DoCmd.OutputTo acOutputReport, stDocName, acFormatXLS, "c:\zzz\signaturedata.xls", True
With oXL.Application
.Visible = True
.Workbooks.Open Filename:=("c:\zzz\ExcelMacros.xls")
x = .Run("TrophySigSheet")
End With
Set oXL = Nothing
The Excel Macro looks like this:
Code:
Windows("signaturedata.xls").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
Workbooks.Open Filename:="c:\zzz\Trophy Sig Sheet.xls", UpdateLinks _
:=3
ActiveWorkbook.Save
This works well but leaves me with two workbooks open - Trophy Sig Sheet and ExcelMacros. I have tried various ways to get the ExcelMacros workbook to close but each time I end up with an Access error message.
Can anyone please advise how I can modify either the Access or Excel codes to get the ExcelMacros workbook to close and leave just the Trophy Sig Sheet workbook open.
Thanks a lot
John