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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,090
Latest member
vivek chauhan

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