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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
This looks like a super simple issue. Your SAVE button is assigned a macro called 'SaveAs'. If you reassign it to the macro called 'SaveInvoice' it works straight away.
 
Upvote 0
hmmm?
What the heck:)
I did as you said and I am still getting the same Run-time error 1004.

My future intention is to call SaveInvoice from the SaveAs macro

Screenshot 2023-03-30 at 7.49.10 PM.png
 
Upvote 0
I took a look at your SaveAs function...there is a 'End With' command near the end that doesn't belong. I commented that out, then uncommented your call to the SaveInvoice routine...and it works perfectly.

Try this: Invoice template v4.xlsm
 
Upvote 0
Good catch!!

I have something going on here then, as that didn't change anything on my end.
I am using a Mac, I wonder if that has a bearing on it?
Thank you so much for the help!!!
Tom
 
Upvote 0
I think you have to define your Range more specifically. i.e.
VBA Code:
Dim sht as WorkSheet
Set sht = ActiveSheet ' or whatever your sheet name is
fName = sht.Range("g9") & sht.Range("h9")
 
Upvote 0
Hi Skybot
Thankyou for your reply
I got rid of the range and just put a static name in and it still hangs on the saveName line.
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:=saveName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
      End If
      
End Sub
 
Upvote 0
Upvote 0
Try this:
Sub SaveInvoice()

VBA Code:
Dim fname As String
fname = "test"

        'MsgBox (fname)
       
            saveName = ThisWorkbook.Name
      
      If saveName <> False Then
            ActiveWorkbook.SaveAs FileName:=saveName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
      End If
      
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,845
Members
449,471
Latest member
lachbee

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