VBA code to open the SAVE AS dialogue box

ExcelPhil

New Member
Joined
Feb 21, 2010
Messages
35
Hi guys,

I'm after VBA code to open the SAVE AS dialogue box where the file name is extracted from cell M1 and the save folder is extracted from cell M2.

The folder address in M2 is the starting point of where the file will be saved.

That folder has many other sub folders that the user could then save the folder to or perhaps even create a new sub folder to save the file to.

I hope this makes sense.

Any help would be appreciated.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi ExcelPhil,

you should have given information about what is to be found in the cells.

Maybe start from this:

VBA Code:
Public Sub MrE_1226317_170080A()
' https://www.mrexcel.com/board/threads/vba-code-to-open-the-save-as-dialogue-box.1226317/

Dim varSaveFName As Variant
Dim strPath As String
Dim strFName As String

Const cstrExt As String = ".xlsm"

strPath = Range("M2").Value
If Right(strPath, 1) <> "\" Then
  strPath = strPath & "\"
End If
strFName = Range("M1").Value
If InStr(strFName, ".") = 0 Then strFName = strFName & cstrExt
varSaveFName = Application.GetSaveAsFilename( _
    InitialFileName:=strPath & strFName, _
    fileFilter:="Excel workbook with Makro ((*.xlsm), *.xlsm")
If VarType(varSaveFName) = vbString Then
  ThisWorkbook.SaveAs Filename:=varSaveFName, _
                      FileFormat:=52 'xlOpenXMLWorkbookMacroEnabled
Else
  MsgBox "User cancelled!", vbOKOnly + vbExclamation
End If
End Sub

Ciao,
Holger
 
Upvote 0
Solution
Hi ExcelPhil,

you should have given information about what is to be found in the cells.

Maybe start from this:

VBA Code:
Public Sub MrE_1226317_170080A()
' https://www.mrexcel.com/board/threads/vba-code-to-open-the-save-as-dialogue-box.1226317/

Dim varSaveFName As Variant
Dim strPath As String
Dim strFName As String

Const cstrExt As String = ".xlsm"

strPath = Range("M2").Value
If Right(strPath, 1) <> "\" Then
  strPath = strPath & "\"
End If
strFName = Range("M1").Value
If InStr(strFName, ".") = 0 Then strFName = strFName & cstrExt
varSaveFName = Application.GetSaveAsFilename( _
    InitialFileName:=strPath & strFName, _
    fileFilter:="Excel workbook with Makro ((*.xlsm), *.xlsm")
If VarType(varSaveFName) = vbString Then
  ThisWorkbook.SaveAs Filename:=varSaveFName, _
                      FileFormat:=52 'xlOpenXMLWorkbookMacroEnabled
Else
  MsgBox "User cancelled!", vbOKOnly + vbExclamation
End If
End Sub

Ciao,
Holger
Thanks Holger, thats works perfectly. You are a legend!
 
Upvote 0

Forum statistics

Threads
1,224,621
Messages
6,179,938
Members
452,949
Latest member
beartooth91

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