VBA to save AND save as using command button and display message box

charliew

Board Regular
Joined
Feb 20, 2018
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to get a workbook to save using a command button so I can get a weekly log of what has changed in the spreadsheet. I need the "master" spreadsheet to save AND a separate workbook saving with the filename of the date it was saved...I can't get the first bit to work, so it saves a copy with the correct filename and displays the message box, but i want the original workbook to save as well...
So i will always have a workbook called "flam bay" which is the copy that is the working copy...and then a weekly workbook so i can see the stock changes in that bay.

I hope that makes sense...

VBA Code:
Private Sub CommandButton1_Click()


Dim CurrDate As String

CurrDate = Format(Date, "DD.MM.YY")

ActiveWorkbook.SaveAs Filename:="U:\Operations, Compliance, SHE & Quality\Technical\Chemists\Flam Bay\" & fName & "\Flam Bay" & fName & " - " & CurrDate & ".xlsm" _

MsgBox "Workbook Saved!", vbInformation, "Check"

End Sub

I'd also like it to email a copy under the same filename to a specified email address...but i don't know where to start with this....

Thank you so much in advance...
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Thank you so much...i can't get this to work either!

I'm getting a "run-time 424" error "object required"

VBA Code:
SaveCopyAs.ActiveWorkbook.SaveAs Filename:="U:\Operations, Compliance, SHE & Quality\Technical\Chemists\Flam Bay\" & fName & "\Flam Bay" & fName & " - " & CurrDate & ".xlsm" _
 
Upvote 0
Run-time error 1004 :cry:

VBA Code:
Private Sub CommandButton1_Click()


Dim CurrDate As String

CurrDate = Format(Date, "DD.MM.YY")

ActiveWorkbook.SaveCopyAs Filename:="U:\Operations, Compliance, SHE & Quality\Technical\Chemists\Flam Bay\" & fName & "\Flam Bay" & fName & " - " & CurrDate & ".xlsm" _

MsgBox "Workbook Saved!", vbInformation, "Check"

End Sub
 
Upvote 0
1708606011132.png


Sorry!

the file hasn't moved or changed name...I'm having a play with it but can't get it to work...
 
Upvote 0
i figured it out...didn't notice the extra /

do you know how i can get it to email a copy as well?
 
Upvote 0
You could try the SendMail method of the workbook:

VBA Code:
ActiveWorkbook.SendMail "someone@yourcompany.com", "Sending you this workbook"
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

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