Before_Save event

viper

Active Member
Joined
Feb 15, 2002
Messages
382
Here's my code in the before_save event of the workbook.

If ActiveWorksheet = Sheets("Sheet5") Then
Sheets("Sheet1").Activate
else
Exit Sub
End if

I previously had only the second line and it worked great but do to user complaints of the workbook activating sheet 1 before it saved I need to change it so that it will only activate sheet 1 before it saves if the active sheet at the time of save is sheet 5.

I am getting an error on the first line of the above code. What's wrong?

thanks,
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Can't explain exatly why, but this code works:

If ActiveSheet.Name = "Sheet5" Then
Sheets("Sheet1").Activate
Else
Exit Sub
End If

I would guess that ActiveWorksheet and the Sheets objects are not directly comparable.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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