Firstly, Happy New Year to all and hope that this year will be a lot better than the last.
I have the following in a macro. It opens an Excel Template called Buylist V2.xltm, unprotect a sheet, populate a cell, protect the sheet that was just unprotected and finally save the template file as just a Macro Enabled file with an .xlsm extension.
All variable have been defined as Dim the code is as follows:-
The problem I am facing is that if the file I am trying to save exists, it just shows the Opened Template, and the macro doesn’t even show the MSGBOX, and it STOPS.
My understanding was that the Application.DisplayAlerts = False would stop giving the message that the file exists and do you want to save, exit…. And that the file would be forced saved.
I am using this mechanism to force save files elsewhere in the macro and getting the results that I want (i.e. force save).
Any ideas how to get round this or where am I going wrong to force save the file?
I have the following in a macro. It opens an Excel Template called Buylist V2.xltm, unprotect a sheet, populate a cell, protect the sheet that was just unprotected and finally save the template file as just a Macro Enabled file with an .xlsm extension.
All variable have been defined as Dim the code is as follows:-
VBA Code:
Workbooks.Open fPath & "Buylist V2.xltm"
Sheets("Buylist").Unprotect
Sheets("Buylist").Select
Range("A1").Value = myYear
ActiveSheet.Range("A3").Select
Sheets("Buylist").Protect
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=fPath & myYear & " Buylist.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
MsgBox (ActiveWorkbook.Name & " has been created and saved." & vbNewLine & vbNewLine _
& "Press OK to confirm the message."), vbOKOnly, Title:=" Create Treasurer's Files"
ActiveWorkbook.Close
Application.DisplayAlerts = True
The problem I am facing is that if the file I am trying to save exists, it just shows the Opened Template, and the macro doesn’t even show the MSGBOX, and it STOPS.
My understanding was that the Application.DisplayAlerts = False would stop giving the message that the file exists and do you want to save, exit…. And that the file would be forced saved.
I am using this mechanism to force save files elsewhere in the macro and getting the results that I want (i.e. force save).
Any ideas how to get round this or where am I going wrong to force save the file?