[VBA HELP] Save file prompt to overwrite, save as or cancel

sasils

New Member
Joined
Jun 3, 2017
Messages
24
Hello,

I need help on VBA for the following requirement.

Pop up message with 3 button of choices
1. Overwrite file
2. Save as different file name
3. Cancel operation.

Thank you so much for your help.

Cheers.....

Sasils
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
7,835
Office Version
2007
Platform
Windows
To customize the text of the buttons in a simple way, it is using a userform:




You can also have 3 buttons with a msgbox.




But I guess the most important thing you need is the code to execute the 3 options. Which of the 2 options do you want?
 

sasils

New Member
Joined
Jun 3, 2017
Messages
24
To customize the text of the buttons in a simple way, it is using a userform:




You can also have 3 buttons with a msgbox.




But I guess the most important thing you need is the code to execute the 3 options. Which of the 2 options do you want?


Hello,

First one please thank you.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
7,835
Office Version
2007
Platform
Windows
Do you know how to create a userform?
Do you need the code for each button or do you already have it?
 

sasils

New Member
Joined
Jun 3, 2017
Messages
24
I need a code for each button.....thanks
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
7,835
Office Version
2007
Platform
Windows
and what do you want to save, a pdf, an excel or what? It would help if you are more specific.
Path, name, sheet, workbook.
 

sasils

New Member
Joined
Jun 3, 2017
Messages
24
and what do you want to save, a pdf, an excel or what? It would help if you are more specific.
Path, name, sheet, workbook.
1. Overwrite file button = Save the whole excel file with the same file name and path
2. Save as = Save the whole excel as new excel .xlsm with same path and let user maintain name
3. Cancel = Cancel operation

thanks
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
7,835
Office Version
2007
Platform
Windows
Create the userform with 3 buttons and put the following code:

Code:
Private Sub CommandButton1_Click()
  ThisWorkbook.Save
  MsgBox "Saved file"
End Sub


Private Sub CommandButton2_Click()
  Application.DisplayAlerts = False
  With Application.FileDialog(msoFileDialogSaveAs)
    .Title = "Save As"
    .AllowMultiSelect = False
    .InitialFileName = ThisWorkbook.FullName
    .FilterIndex = 2
    If .Show Then
      ActiveWorkbook.SaveAs .SelectedItems(1)
      MsgBox "Saved file"
    End If
  End With
End Sub


Private Sub CommandButton3_Click()
  MsgBox "Cancel operation"
  Unload Me
End Sub
 

Forum statistics

Threads
1,078,137
Messages
5,338,458
Members
399,234
Latest member
WaddoAU

Some videos you may like

This Week's Hot Topics

Top