Excel VBA Save As Button

darbymsu1982

New Member
Joined
Sep 8, 2016
Messages
4
I'm trying to create a macro button in my Excel spreadsheet. I can create the button, I just need the code.

I need the 'Save As' dialog box to open. FileName to be the text located in "J15" , the file path to be linked to "K61", and the file type to be ".xlsm"

Can anyone help that knows VBA?

Thanks!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
try this:
Code:
    Dim FilenameSaveAs As String
    
    ChDir (ThisWorkbook.Worksheets("Sheet1").Range("K61"))
    FilenameSaveAs = Application.GetSaveAsFilename(InitialFileName:=ThisWorkbook.Worksheets("Sheet1").Range("J15"), fileFilter:="Microsoft Excel Macro-Workbook (*.xlsm), *.xlsm")
    If FilenameSaveAs <> "False" Then
        ActiveWorkbook.SaveAs Filename:=FilenameSaveAs, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
        Else
        MsgBox "File not saved", vbInformation, "Saving Cancelled"
    End If

P.S.: for ChDir to work you may need to use ChDrive as well.
 
Last edited:
Upvote 0
Almost there, but doesn't actually Save...



Sub FileName_Cellvalue()
'DialogBox Opens
'J15 is added to Save line w/ "Quote"
'File Path location works correctly
'Doesn't Actually Save
Dim fPth As Object
Dim Path As String
Dim FileExtStr As String
Path = Sheets(1).Range("K61").Text
FileName = Sheets(1).Range("J15").Text + " - Quote"
FileExtStr = ".xlsm": FileFormat = xlOpenXMLWorkbookMacroEnabled
Set fPth = Application.FileDialog(msoFileDialogSaveAs)


With fPth
.InitialFileName = Path & FileName & FileExtStr
.Title = "Save As"
.InitialView = msoFileDialogViewList
.Show
End With


End Sub




I'm trying to create a macro button in my Excel spreadsheet. I can create the button, I just need the code.

I need the 'Save As' dialog box to open. FileName to be the text located in "J15" , the file path to be linked to "K61", and the file type to be ".xlsm"

Can anyone help that knows VBA?

Thanks!
 
Upvote 0
Thanks so much for your response. I've been trying to get yours to work all day..

It gives me an Error "Run-Time Error (Error 9) Subscript out of range"

Points to your ChDir... line...

I tried adding the ChDrive line as directed to no avail.

The source directory will be different locations on the "S:"
 
Upvote 0
I would guess the error is to do with the part after ChDir :
Code:
ChDir (ThisWorkbook.Worksheets("[COLOR=#ff0000]Sheet1[/COLOR]").Range("K61"))
maybe you don't have a sheet named "Sheet1" - change the red to your sheet's name.
or use the thing that works for you:
Sheets(1).Range("K61").Text

I guess the same error will appear on the next line as well.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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