[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
8,735
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
8,735
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
8,735
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
8,735
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,081,538
Messages
5,359,396
Members
400,526
Latest member
Brook1083

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top