Adding a message box to inform Macro has run

BMWE65

New Member
Joined
Mar 19, 2011
Messages
10
Hi all,

Just another quick question regarding some macro code I have.
I have 2 buttons, each with their own macro.

Button/Macro 1 is:

Public Sub SaveAsC6()
ThisFile = Range("C6").Value
ThisFile2 = Range("E5").Value
ActiveWorkbook.SaveAs Filename:=ThisFile & "-" & ThisFile2 & "-" & Format(Date, "yyyymmdd")
End Sub

When clicking this Macro, it saves the file, using the data in cells C6, E5 and today's date as the filename.

What I would like to do is add a message box that comes up to confirm to me that the save has been successful after the button has been pressed/saved. Can anyone tell what code I need to add?
The message box can say something along the lines of 'Save Successful'.



Button/Macro 2 is:

Sub CloseWorkbook()
ThisWorkbook.Close Saved = True
End Sub


Upon pressing this button, Excel closes the workbook. However, before closing it, I would like a message box coming up, asking me 'Are you sure you want to exit'?

Thanks! :)
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Something like this at the end of your code should do what you need.

Code:
MsgBox("'Save Successful")
 
Upvote 0
Hi. Try these

Code:
Public Sub SaveAsC6()
ThisFile = Range("C6").Value
ThisFile2 = Range("E5").Value
ActiveWorkbook.SaveAs Filename:=ThisFile & "-" & ThisFile2 & "-" & Format(Date, "yyyymmdd")
If Err = 0 Then MsgBox "Save successful", vbInformation
End Sub

Sub CloseWorkbook()
If MsgBox("Are you sure you want to exit", vbQuestion + vbYesNo) = vbYes Then ThisWorkbook.Close Saved = True
End Sub
 
Upvote 0
Thanks both.

VoG - that is prefect - thank you.
Hopefully my new invoice system that I've been working on for the last few days will make my life a bit easier!

:)
 
Upvote 0
Just to piggy back an additional question, hope the OP doesn't mind!

If I have a macro that does

Code:
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & Prefix & sh.Name & ".xls"

what would I need to add to the message box to tell the user *where* any files have been saved?

The message would read something like "File has been saved successfully to" and then the path.

TIA
 
Upvote 0
Try

Code:
MsgBox "File has been saved successfully to " & ActiveWorkbook.Path
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,633
Members
452,933
Latest member
patv

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