fill in File Name and SaveAs .xlsm

Wizcow

New Member
Joined
Mar 29, 2023
Messages
12
Office Version
  1. 365
Platform
  1. MacOS
Hello
My button is to open the SaveAs dialog box so the user can pick the path for the worksheet.
II would like the file name and file type pre-filled in on the SaveAs dialog box

here is my 'not working' code

Rich (BB code):
Sub Button72_Click()

Dim fname As String
fname = Range("g9") & Range("h9")

       Application.GetSaveAsFilename , (fname)
      ThisWorkbook.SaveAs FileName:=fname, FileFormat:=52
   
End Sub

This code launches the Save dialog box but doesn't fill in the 'Save As' or 'File Format' boxes
If I click the 'Save' button on the dialog box it saves a file with the correct name but no .xlsm extension making the file unusable unless you manually add the extension.

Anyone see the issue?
Thanx
Tom
 
VBA Code:
Sub SaveInvoice()

Dim fname As String
fname = "test"

        'MsgBox (fname)
       
            saveName = Application.GetSaveAsFilename(InitialFileName:=fname, _
            fileFilter:="Microsoft Excel Worksheet (*.xlsm), *.xlsm")
      
      If saveName <> False Then
            ActiveWorkbook.SaveAs FileName:=fname, FileFormat:=xlOpenXMLWorkbookMacroEnabled
      End If
      
End Sub
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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