Filling Save-As file name window

MAM8433

New Member
Joined
May 18, 2011
Messages
44
My goal is to have the Save-as dialog box open at the end of the macro and to offer the xlsx format only, so that the VBA code will be dropped when the file is closed.

I worked on this task in a copy of my original macro file and it works (see code below). It even fills the file name window with the current file name.

When I pasted this same code into the original file, why would the file name window be empty? Everything else works. Is there another way to force the file name into the window? Is my original file corrupted? Could Windows 10 be a factor? Development of the original file started off in Win7. I'm a journeyman when it comes to VBA and this is new territory for me.

VBA Code:
Sub SaveAs()
Dim FileName As Variant
Dim txtMacroFile, txtFileName As String

txtMacroFile = ActiveWorkbook.Name
txtFileName = Replace(txtMacroFile, ".xlsm", "")
Application.DisplayAlerts = False
FileName = Application.GetSaveAsFilename(txtFileName, filefilter:="Excel Files (*.xlsx), *.xlsx")
If FileName = "False" Then Exit Sub
ActiveWorkbook.SaveAs FileName:=FileName, FileFormat:=51
Application.DisplayAlerts = True
End Sub

Thank you in advance for any insights or code improvements.
 
Last edited by a moderator:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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