Solved SaveAs not erroring, but doesn't appear to do anything (1 Viewer)

Alc

Registered User.
Local time
Today, 17:56
Joined
Mar 23, 2007
Messages
2,407
I have the following code which I found online in a standalone sub procedure, just to test it out for future use.
It's in Access 2010, in case that makes a difference.

Code:
                Dim xlApp As Excel.Application
                Dim xlWB As Excel.Workbook
                Dim strMasterBook as string

                strMasterBook = "P:\QE\New Model Activity\Automobile\PQS\IQS project\PQS data\_2022\AllData_2022.xlsm"
               
                Set xlApp = New Excel.Application
                xlApp.Visible = True
                Set xlWB = xlApp.Workbooks.Add
    MsgBox "5"
                xlWB.SaveAs strMasterBook
    MsgBox "6"
                xlWB.Close SaveChanges:=False
                Set xlWB = Nothing
                xlApp.Quit
                Set xlApp = Nothing

The code runs as far as opening Excel and producing Msgbox "5", then skips straight to the end.
No error message is displayed, but it's not saving the file and it's ignoring the rest of the code and leaving an Excel process hanging.
I figure there has to be something simple I'm missing.

I've debugged to confirm that strMasterBook is correctly set.
I've tried hard coding in the filepath, in case the variable was causing the problem.

Any ideas?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:56
Joined
May 7, 2009
Messages
19,245
do you have all the folders and subfolders on P:
do you have Right to Create in that folder?
 

Alc

Registered User.
Local time
Today, 17:56
Joined
Mar 23, 2007
Messages
2,407
do you have all the folders and subfolders on P:
do you have Right to Create in that folder?
Yes and yes.
I should have said, I can manually create that file without any problems.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:56
Joined
May 7, 2009
Messages
19,245
you did not Specify the Format of the workbook (which is Macro Enabled):

..
..
xlWB.SaveAs strMasterBook, xlOpenXMLWorkbookMacroEnabled '52
 

Minty

AWF VIP
Local time
Today, 22:56
Joined
Jul 26, 2013
Messages
10,371
I think you need to close the App workbook to prevent the Excel process from being left behind.

xlApp.Workbooks.Close
Set xlApp = Nothing
 

Alc

Registered User.
Local time
Today, 17:56
Joined
Mar 23, 2007
Messages
2,407
you did not Specify the Format of the workbook (which is Macro Enabled):

..
..
xlWB.SaveAs strMasterBook, xlOpenXMLWorkbookMacroEnabled '52
Thank you! I knew it wouldn't be something complicated.
Works like a charm now.
 

Alc

Registered User.
Local time
Today, 17:56
Joined
Mar 23, 2007
Messages
2,407
I think you need to close the App workbook to prevent the Excel process from being left behind.

xlApp.Workbooks.Close
Set xlApp = Nothing
Thanks.
Once I got past the 'save' problem, the process did close as wanted.
 

Users who are viewing this thread

Top Bottom