I have an Excel ss that I open with a command button on a form in Access. I want to have another button on the form to close the ss after making changes to ss and save it with a different filename.
My code for the close button is as follows:
Private Sub CmdCloseSave_Click()
On Error GoTo Err_CmdCloseSave_Click
Dim oApp As Excel.Application
Dim objActiveWkb As Excel.Workbook
Dim fName As String
Dim wInfo As String
wInfo = Forms![frmDay]![WellID]
fName = DBPath & "PipeTally2-" & wInfo & ".xls"
Set oApp = GetObject(, "Excel.Application"
Set objActiveWkb = oApp.ActiveWorkbook
objActiveWkb.Close SaveChanges:=True, Filename:=fName
oApp.Quit
'Clear the object variable.
If fIsAppRunning("Excel" Then
If fCloseApp("XLMAIN" Then
End If
End If
It tells me that object variable or With block variable not set. This is happening at the objActiveWkb.close line of code.
I had it working with a similar db, but it will not work here. I know that if I only set the worksheet object, the binding does not occur until the code is run and I'll get an error message as above, but I don't see my problem.
Thanks in advance.
My code for the close button is as follows:
Private Sub CmdCloseSave_Click()
On Error GoTo Err_CmdCloseSave_Click
Dim oApp As Excel.Application
Dim objActiveWkb As Excel.Workbook
Dim fName As String
Dim wInfo As String
wInfo = Forms![frmDay]![WellID]
fName = DBPath & "PipeTally2-" & wInfo & ".xls"
Set oApp = GetObject(, "Excel.Application"
Set objActiveWkb = oApp.ActiveWorkbook
objActiveWkb.Close SaveChanges:=True, Filename:=fName
oApp.Quit
'Clear the object variable.
If fIsAppRunning("Excel" Then
If fCloseApp("XLMAIN" Then
End If
End If
It tells me that object variable or With block variable not set. This is happening at the objActiveWkb.close line of code.
I had it working with a similar db, but it will not work here. I know that if I only set the worksheet object, the binding does not occur until the code is run and I'll get an error message as above, but I don't see my problem.
Thanks in advance.