GetSaveAsFilename ([initialfilename]) not populating

maruapo

New Member
Joined
Aug 30, 2005
Messages
21
My company is behind the times and I'm forced to code everything so that all workbooks are saved in XLS format (not XLSX or XLSM). To force this I added the following code to the 'main' macro whose primary purpose is to prepare a sheet so that about 25 other macros are able to work on it. The problem is I can't get [initialfilename] to populate. If I put it in quotes it works, but if I put a variable there it's just blank in the dialog box. The variable isn't bad either... I can hover over the variable name in VBE and see that the variable is populated, but that name refuses to appear in the dialog box.

At first I had no [initialfilename] in place, just a comma, since it's SUPPOSED to auto-populate the default filename (like this: x = Application.GetSaveAsFilename(, "Excel 97-2003 Workbook (*.xls), *.xls")) But that didn't work either. I've tried saving the document first so it has a 'fresh' name attached to it, but nope. I've redefined the variables from strings to variants and everything in between. Nothing works.

The only times I can get GetSaveAsFilename to work is when I put [initialfilename] in quotes... but that's no good because the filename changes every time the file is run so I can't hardcode it like that.

Below is the relevant snippet. What am I doing wrong?

dim a1 as workbook
dim a as string
dim x as variant

Set a1 = ActiveWorkbook
a = a1.name

x = Application.GetSaveAsFilename(a, "Excel 97-2003 Workbook (*.xls), *.xls")
If x = False Then Exit Sub
ActiveWorkbook.SaveAs Filename:=x, FileFormat:=xlExcel8
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi,
try adding the InitialFileName & FileFilter arguments & see if that helps:

x = Application.GetSaveAsFilename(InitialFileName:=a, FileFilter:="Excel 97-2003 Workbook (*.xls), *.xls")

Dave
 
Last edited:
Upvote 0
Hi,
try adding the InitialFileName & FileFilter arguments & see if that helps:

x = Application.GetSaveAsFilename(InitialFileName:=a, FileFilter:="Excel 97-2003 Workbook (*.xls), *.xls")

Dave

Yeah, I tried that already. Doesn't make a difference... still results in blank file name in the dialog box.
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,141
Members
448,948
Latest member
spamiki

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