[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,844
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,844
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,844
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,844
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,082,115
Messages
5,363,247
Members
400,722
Latest member
DrewPop24

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top