Hi there.
I am developing a macro-enabled workbook for distribution to a variety of co-workers. I'm planning on distributing a macro-enabled template (XLTM). I'm struggling with code to do the following:
Upon opening the XLTM file (by simply double-clicking), I'd like the user to be forced to save the file locally as an macro-enabled workbook (.XLSM).
I've taken several stabs at code to bring up the Save As dialog, all of which appear to be functioning as expected, but none of them actually results in the file being saved.
Here's four strings of code I have tried, all placed in the ThisWorkbook object in the midst of a Workbook_Open subroutine:
'ATTEMPT 1:
Application.Dialogs(xlDialogSaveAs).Show "PROJECT NAME - Project Audit (YYYY-MM-DD).xlsm"
'ATTEMPT 2:
Application.GetSaveAsFilename _
InitialFileName:=PROJECT NAME - Project Audit (YYYY-MM-DD).xlsm
'ATTEMPT 3:
Dim bFileSaveAs As Boolean
bFileSaveAs = Application.Dialogs(xlDialogSaveAs).Show
If Not bFileSaveAs Then MsgBox "User cancelled", vbCritical
'ATTEMPT 4:
Dim fNameAndPath As Variant
fNameAndPath = Application.GetSaveAsFilename(InitialFileName:="PROJECT NAME - Project Audit (YYYY-MM-DD).xlsm", fileFilter:="Macro-Enabled Workbook (*.xlsm), *.xlsm", Title:="Save As")
If fNameAndPath = False Then Exit Sub
Me.SaveAs Filename:=fNameAndPath
Help!
I'm using Excel 2007, BTW (if it wasn't already obvious).
Thanks.
I am developing a macro-enabled workbook for distribution to a variety of co-workers. I'm planning on distributing a macro-enabled template (XLTM). I'm struggling with code to do the following:
Upon opening the XLTM file (by simply double-clicking), I'd like the user to be forced to save the file locally as an macro-enabled workbook (.XLSM).
I've taken several stabs at code to bring up the Save As dialog, all of which appear to be functioning as expected, but none of them actually results in the file being saved.
Here's four strings of code I have tried, all placed in the ThisWorkbook object in the midst of a Workbook_Open subroutine:
'ATTEMPT 1:
Application.Dialogs(xlDialogSaveAs).Show "PROJECT NAME - Project Audit (YYYY-MM-DD).xlsm"
'ATTEMPT 2:
Application.GetSaveAsFilename _
InitialFileName:=PROJECT NAME - Project Audit (YYYY-MM-DD).xlsm
'ATTEMPT 3:
Dim bFileSaveAs As Boolean
bFileSaveAs = Application.Dialogs(xlDialogSaveAs).Show
If Not bFileSaveAs Then MsgBox "User cancelled", vbCritical
'ATTEMPT 4:
Dim fNameAndPath As Variant
fNameAndPath = Application.GetSaveAsFilename(InitialFileName:="PROJECT NAME - Project Audit (YYYY-MM-DD).xlsm", fileFilter:="Macro-Enabled Workbook (*.xlsm), *.xlsm", Title:="Save As")
If fNameAndPath = False Then Exit Sub
Me.SaveAs Filename:=fNameAndPath
Help!
I'm using Excel 2007, BTW (if it wasn't already obvious).
Thanks.
Last edited: