Excel VBA Save As

shapeshiftingkiwi

New Member
Joined
Mar 31, 2021
Messages
33
Office Version
  1. 365
Platform
  1. Windows
I'm trying to create a save as button in excel and adapted the below code from a video guide. However whenever I click on the button or hit the code to run, nothing happens. The macro is linked to the button and the button does "depress" to show it was clicked. What am I missing?

Sub Save_As()
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save"
.ButtonName = "Save Form"
.InitialFileName = "C:\Users\MYNAME\OneDrive - MY COMPANY\Documents\Excel\" & Range("M3").Value
End With
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Sub Save_As()
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save"
.ButtonName = "Save Form"
.InitialFileName = "C:\Users\MYNAME\OneDrive - MY COMPANY\Documents\Excel\" & Range("M3").Value
.Show
End With
End Sub
 
Upvote 0
Hmm, so that now brings the pop up up but when it's saved it doesn't actually seem to appear in that pathway. I found another method. Below the Save_As sub correctly saves the sheet but there's no pop up (which I want) and the Save_As2 sub has the pop up but it doesn't actually save. Any idea how to get the pop up and get it to save?

Sub Save_As()
Dim path As String
Dim filename1 As String

path = "P:\COMPANY - Production\Production Form Save As Test\" & Range("Save_As!M3").Value
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=path & filename1 & ".xlsx", FileFormat:=xlOpenXMLWorkbook

End Sub
___________________________
Sub Save_As2()
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save"
.ButtonName = "Save Form"
.InitialFileName = "P:\COMPANY - Production\Production Form Save As Test\" & Range("Save_As!M3").Value
.Show
End With

End Sub
 
Upvote 0
Hmm I still can't figure it out. The answer may be in there but my knowledge isn't enough to spot it and adapt it to my code. Any ideas? This code successfully saves it in the right spot but it doesn't have to pop up showing where it's going to save.

Sub Save_As()
Dim path As String
Dim filename1 As String

path = "P:\COMPANY - Production\Production Form Save As Test\" & Range("Save_As!M3").Value
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=path & filename1 & ".xlsx", FileFormat:=xlOpenXMLWorkbook

End Sub


This has the pop up showing the folder it's going to save in and what it's going to be called but it doesn't actually save when I click save.

Sub Save_As2()
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save"
.ButtonName = "Save Form"
.InitialFileName = "P:\COMPANY - Production\Production Form Save As Test\" & Range("Save_As!M3").Value
.Show
End With
End Sub
 
Upvote 0
I have this code that works great but after I click "Save Form" and go to the pathway it was supposed to save, it's not there. How can I get this to actually save?

Sub Save_As2()
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save"
.ButtonName = "Save Form"
.InitialFileName = "P:\COMPANY NAME - Production\Production Form Save As Test\" & Range("Save_As!M3").Value
.Show
End With
End Sub
 
Upvote 0
There's nothing in that code that saves the file. The dialog button does not perform that function - you need to use the Execute method of the dialog. I've never used that dialog but I think you'd need

VBA Code:
With Application.FileDialog(msoFileDialogSaveAs)
   .Title = "Save"
   .ButtonName = "Save Form"
   .InitialFileName = "P:\COMPANY NAME - Production\Production Form Save As Test\" & Range("Save_As!M3").Value
   If .Show Then
      .Execute
   End If 'or Else or ElseIf might go here
End With
 
Upvote 0
Solution
Try adding .Execute before the End With
 
Upvote 0
Ended up using this.


With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save"
.ButtonName = "Save Form"
.InitialFileName = "P:\COMPANY NAME - Production\Production Form Save As Test\" & Range("Save_As!M3").Value
If .Show Then
.Execute
End If 'or Else or ElseIf might go here
End With
 
Upvote 0

Forum statistics

Threads
1,215,516
Messages
6,125,280
Members
449,220
Latest member
Excel Master

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