rjplante
Well-known Member
- Joined
- Oct 31, 2008
- Messages
- 574
- Office Version
- 365
- Platform
- Windows
I have an Excel 2003 compatible spreadsheet template file. I want to have a dialog box open as the workbook opens for the first time forcing the user to save the file as an .xls or .xlsm format. This would preserve the template from tampering. I have a cell that gets changed so that when the saved file is opened it will not launch a save as dialogue every time.
I want to force the user to save the file. To that end I have a msgbox that reiterates the save request should they click cancel. The problem I have is that instead of reopening the save as dialog box when they click OK on my message box, it opens a small box that says
"A file name "False" already exists in this location. Do you want to replace it?" (YES, NO, CANCEL).
If I click cancel in this box my macro crashes with a run time error 1004, and the message "Method 'Save As' of object '_workbook' failed."
I would like to have the user forced to enter a name and not be allowed to cancel out of the dialog box. I want the template file preserved without changes so that it is always the same each time they open it.
Thanks for the help.
Robert
I want to force the user to save the file. To that end I have a msgbox that reiterates the save request should they click cancel. The problem I have is that instead of reopening the save as dialog box when they click OK on my message box, it opens a small box that says
"A file name "False" already exists in this location. Do you want to replace it?" (YES, NO, CANCEL).
If I click cancel in this box my macro crashes with a run time error 1004, and the message "Method 'Save As' of object '_workbook' failed."
I would like to have the user forced to enter a name and not be allowed to cancel out of the dialog box. I want the template file preserved without changes so that it is always the same each time they open it.
Thanks for the help.
Robert
Rich (BB code):
Private Sub Workbook_Open()
Dim fName As String
If Range("CA1").Value <> "" Then
Exit Sub
Else
fName = Application.GetSaveAsFilename(, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")
If fName = False Then
MsgBox "Please enter a file name and select a location.", vbOKOnly
Cancel = True
Application.EnableEvents = False
'**** code crashes here on this next line *****
ThisWorkbook.SaveAs Filename:=fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Application.EnableEvents = True
Range("CA1").Value = "Saved"
End If
Application.EnableEvents = False
ThisWorkbook.SaveAs Filename:=fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Range("CA1").Value = "Saved"
Application.EnableEvents = True
End If
End Sub