Filling Save-As file name window

MAM8433

New Member
Joined
May 18, 2011
Messages
35
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:

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Watch MrExcel Video

Forum statistics

Threads
1,122,246
Messages
5,595,044
Members
413,963
Latest member
teggl97

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
Top