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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
try this

VBA Code:
Sub saveasname()

Dim fname As String
fname = Range("g9") & Range("h9")
       
       saveName = Application.GetSaveAsFilename(InitialFileName:=fname, _
                                         fileFilter:="Microsoft Excel Worksheet (*.xlsm), *.xlsm")
      If saveName <> False Then
        ActiveWorkbook.SaveAs fileName:=saveName
      End If
      

End Sub
 
Upvote 0
Thank you for your reply I_know_nuffin!
I tried your example but I get an error

Run-time error '1004':
Method 'GetSaveAsFilename' of object '_Application' failed

Any ideas what could cause this?
Thanks again!!
Tom
Screenshot 2023-03-30 at 9.19.35 AM.png
 
Upvote 0
try changing line 3 to this:

VBA Code:
fname = Range("g9").value & Range("h9").value
 
Upvote 0
Thank you Candyman8019

Dang!
Same error still

Thank you
Tom
 
Upvote 0
Are there any values in G9 or H9 that would be considered invalid characters for a filename?
Try adding:
msgbox fname

to make sure you're result is a valid path and filename.
 
Upvote 0
Candyman8019
That part of the code seems to work fine.
I tested with a message box and it brings back the value of G9 and H9 perfectly
The debugger hangs on the SaveName part
VBA Code:
MsgBox (fname)
 

Attachments

  • Screenshot 2023-03-30 at 10.33.42 AM.png
    Screenshot 2023-03-30 at 10.33.42 AM.png
    15.4 KB · Views: 10
Upvote 0
How about this:

VBA Code:
Sub saveasname()

Dim fname As String
fname = Range("g9").value & Range("h9").value
       
       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
Dang it!
The same error on the saveName line
I sure appreciate your effort
Tom
 
Upvote 0
something odd seems to be going on. Any chance you could share a copy of your workbook using dropbox or onedrive so I can take a closer look? feel free to sanitize any data as required.
 
Upvote 0

Forum statistics

Threads
1,215,509
Messages
6,125,216
Members
449,215
Latest member
texmansru47

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