Macro keeps asking me if I want to replace file and crashing

ghrek

Active Member
Joined
Jul 29, 2005
Messages
426
Hi

I have the following macro that im trying to run automatically as soon as I click the save button but it keeps asking if I want to replace and then crashes.

Ive put in workbook/before save in the VBA, Im trying to get it to go to sheet called RUNNING TOTALS and update that before saving in the 2 locations in the macro.
One other thing I got and dont know if you can add to it where I have it go to running totals to update sheet can I get to go back to the sheet that I was last using. That bit I know if defentally not in the macro.

Any ideas?

Thanks


VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.save
    Sheets("RUNNING TOTALS").Select
    ActiveWorkbook.save
    ActiveWorkbook.SaveAs Filename:= _
        "T:\Passenger Accounts\Surplus & Loss WA\Surplus & Loss WA P2101 ONWARDS.xlsb" _
        , FileFormat:=xlExcel12, CreateBackup:=False
    ActiveWorkbook.SaveAs Filename:= _
        "[URL='https://arrivagroup.sharepoint.com/teams/MANAGERSSURPLOSSERRORLOG/Shared%20Documents/General/Surplus%20&%20Loss%20WA%20P2101%20ONWARDS.xlsb']https://arrivagroup.sharepoint.com/teams/MANAGERSSURPLOSSERRORLOG/Shared Documents/General/Surplus & Loss WA P2101 ONWARDS.xlsb[/URL]" _
        , FileFormat:=xlExcel12, CreateBackup:=False
    ActiveWorkbook.save
End Sub
 
Last edited by a moderator:

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
It's a before save event so I don't think you can/should code to save within the event unless U want recursion. So in this part of the code U would code to update your running sheets totals only. So you would code to Save As which would cause this event to fire and update your sheet before the save occurred. There's no reason for any sheet selection change to occur by saving but you could easily just add whateversheet.activate after the save. HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,575
Members
449,039
Latest member
Arbind kumar

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