GetSaveAsFilename File Name Won't Display

MAM8433

New Member
Joined
May 18, 2011
Messages
44
I want the user to save the current macro file as a non-macro Excel file. The user controls the file name and file location on a shared network. In the code below, I cannot get the current macro file name to populate the file name window of the Save As dialog box.

Otherwise, the code seems to work, because I can see the 3 Excel format options in the Save as Type window.

I have also tried (InitialFileName:=txtFileName,…), as well as (, Filefilter:=…) and (Filefilter:=…). Each time, the save-as box opens with nothing in the filename window. What am I missing?

My code:

Rich (BB code):
‘Eliminate the macro file extension.
txtMacroFile = ActiveWorkbook.Name
txtFileName = Replace (txtMacroFile, ".xlsm", "")

'Display the saveas dialog box with xlsx as default format

FileName = Application.GetSaveAsFilename(txtFileName, FileFilter:= _
" Excel Macro Free Workbook (*.xlsx), *.xlsx," & _
" Excel 2000-2003 Workbook (*.xls), *.xls," & _
" Excel Binary Workbook (*.xlsb), *.xlsb")

If FileName = "False" Then Exit Sub

ActiveWorkbook.SaveAs FileName:=FileName

Thank you. I hope you can help.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi MAM8433,

if macrofree you should only use xlsx for saving.

Rich (BB code):
ActiveWorkbook.SaveAs FileName:=FileName

Maybe use different names for variables as those of a Parameter used by Excel:

VBA Code:
Dim txtFileName As String, varFileName As Variant
'Eliminate the macro file extension.
txtFileName = Replace(ActiveWorkbook.Name, ".xlsm", "")

'Display the saveas dialog box with xlsx as default format

varFileName = Application.GetSaveAsFilename(txtFileName, FileFilter:= _
  " Excel Macro Free Workbook (*.xlsx), *.xlsx,")

If varFileName = "False" Then Exit Sub
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:=varFileName, FileFormat:=51
Application.DisplayAlerts = True

Ciao,
Holger
 
Upvote 0
Solution
Thanks, Holger: In my case, saving macro-free is paramount. I will restrict users to xlsx. Thank you, again!
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top