VBA for Save as to open open dialog box, populate filename and select same folder as open workbook

leojez

Board Regular
Joined
Apr 12, 2022
Messages
51
Office Version
  1. 365
Platform
  1. Windows
Hello, been trying to figure this out but can't quite get there.

I have a workbook and I've added a button with the following macro attached:

VBA Code:
Sub Save_settings_button()
'
' Save_settings_button
'

'

Worksheets(1).Activate
Application.GetSaveAsFilename

End Sub

This works fine, in that it opens the Save as dialog, however, the filename field is blank, and I'd like this to populate the field with the filename "Portfolio Balance Tool.xlsm" - so the user can then change the filename as required.

Also, the file location goes to my documents folder by default, and I'd like it to select the folder of the open workbook.

Any ideas to update my VBA code? Thank you!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Something like this:
VBA Code:
Sub test()
    Dim vFileSaveName As Variant
    Dim sCurDir As String
    
    On Error GoTo Xit
    
    sCurDir = CurDir
    ChDir ThisWorkbook.Path
    vFileSaveName = Application.GetSaveAsFilename("Portfolio Balance Tool.xlsm", "Excel Files (*.xlsm), *.xlsm")
    
    If vFileSaveName <> False Then
        'save file here.
    Else
        'you cancelled.
    End If
    
Xit:
    ChDir sCurDir
End Sub
 
Upvote 0
Thanks so much for replying! Actually after much trial and error I came up with this, this morning:

VBA Code:
Application.Dialogs(xlDialogSaveAs).Show ("c:\my_folder\Portfolio Balance Tracker")

It seems super simple compared to yours. It does exactly what I want ... do you think there could be anything than could cause issues as it is so simple? Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,463
Members
452,915
Latest member
hannnahheileen

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