From Access I am trying to open an excel file and save it as "score.xls" before importing into access. The following code is what I've come up with. Two issues:
1. If I totally close down access and restart is the first part of the code works, and if excel is not open it will go to the appropriate line. However, if I run it a second time, it does not recognize that Excel is not open and proceeds with the first line of code as if it is open.
2. Since either way works - I apparently don't need to have a worksheet open to perform the SAVE AS function?
Here's the code I've come up with:
Sub DelayedOrderSave()
Dim appXL As Object
On Error Resume Next
'if the application is not running, an error occurs
Set appXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set appXL = CreateObject("Excel.Application")
appXL.Visible = True
End If
'open file
appXL.Workbooks.Open ("C:\WINNT\Profiles\mamicuc\Desktop\Score.xls")
Excel.Application.DisplayAlerts = False
ActiveWorkbook.SaveAs filename:="C:\WINNT\Profiles\mamicuc\Desktop\Score.xls" _
, FileFormat:=xlText, CreateBackup:=False
appXL.Quit
Excel.Application.DisplayAlerts = True
Set appXL = Nothing
End Sub
Any thoughts? Marie[/code]
1. If I totally close down access and restart is the first part of the code works, and if excel is not open it will go to the appropriate line. However, if I run it a second time, it does not recognize that Excel is not open and proceeds with the first line of code as if it is open.
2. Since either way works - I apparently don't need to have a worksheet open to perform the SAVE AS function?
Here's the code I've come up with:
Sub DelayedOrderSave()
Dim appXL As Object
On Error Resume Next
'if the application is not running, an error occurs
Set appXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set appXL = CreateObject("Excel.Application")
appXL.Visible = True
End If
'open file
appXL.Workbooks.Open ("C:\WINNT\Profiles\mamicuc\Desktop\Score.xls")
Excel.Application.DisplayAlerts = False
ActiveWorkbook.SaveAs filename:="C:\WINNT\Profiles\mamicuc\Desktop\Score.xls" _
, FileFormat:=xlText, CreateBackup:=False
appXL.Quit
Excel.Application.DisplayAlerts = True
Set appXL = Nothing
End Sub
Any thoughts? Marie[/code]