Combinig before events on a workbook

Rosing

New Member
Joined
Apr 3, 2014
Messages
3
Hi

How do I combine several before events in ThisWorkbook?

I need to use all three

BeforeClose, BeforeSave & BeforeOpen

Thanks in anticipation
 

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
You don't combine them. You just include them one after the other (in any order) in the ThisWorkbook module.

It is Open not BeforeOpen.
 
Upvote 0
You don't combine them. You just include them one after the other (in any order) in the ThisWorkbook module.

It is Open not BeforeOpen.

Thanks

I receive an error message (Compile error) when I use this code in ThisWorkbook in vba

Private sub Workbook_Open ()
>code<
End sub

Private sub Workbook_BeforeSave ()
>code<
End sub

Private sub Workbook_BeforeClose ()
>code<
End sub

Do you know why?

Thnaks in anticipation
 
Upvote 0
I use this code
And it stops at Private Sub Workbook_BeforeClose when I save the file

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("Log").Visible = True
Sheets("Log").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveCell = Environ("username")
ActiveCell.Offset(0, 1).Select
Selection.FormulaR1C1 = "=NOW()"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Sheets("Log").Visible = xlVeryHidden
Sheets("Marketing budget").Select
Range("Table1[[#Headers],[Projekt]]").Select
End Sub

Private Sub Workbook_BeforeClose()
Sheets("Account").Select
Range("account[[#Headers],[Account]]").Select
End Sub
 
Upvote 0
Maybe som4ething like

Range("A1").select instead of

Range("account[[#Headers],[Account]]").Select
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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