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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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