Opens the save box but doesn't save the file

Sypher

New Member
Joined
Apr 5, 2023
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
I have this code attached to a button to rename and save the file where the user likes but the issue is that the file doesn't end up actually saving.

Here is the code below:

Private Sub CommandButton1_Click()
Dim IntialName As String
Dim fileSaveName As Variant
Dim equipment As Range
Dim employee As Range
Dim ws As Worksheet

Set ws = Worksheets("Fillable")

Set equipment = ws.Range("C9")
Set employee = ws.Range("G11")

InitialName = equipment & "_" & employee & "_Report"
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitialName, _
fileFilter:="Excel Files (*.xls), *.xlsm")

If fileSaveName <> False Then
MsgBox "Save as " & fileSaveName
End If

End Sub

Any help is appreciated!!!
 

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
Couple of things. Firstly, get in the habit of putting Option Explicit at the top of your Sub. That way you would have discovered that you declared IntialName As String but later in your code you tried to use InitialName as the string - notice the difference?
Secondly, you don't actually have any code line command that saves the file. The message box does nothing. You need something like:
VBA Code:
ThisWorkbook.SaveAs fileSaveName
to actually save the file.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,103
Messages
6,123,108
Members
449,096
Latest member
provoking

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