Help with WorkbookBeforeClose

huzman

New Member
Joined
Oct 2, 2003
Messages
29
Hi All!

How do I use this:

Private Sub object_WorkbookBeforeClose(ByVal Wb As Workbook, ByVal Cancel As Boolean)

what's an object? how do i declare it?

I want to use this as i want something to happen immediately before the workbook closes.

Thanks!!
 

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Iridium

Well-known Member
Joined
Jul 15, 2002
Messages
2,831
Would the Workbook_BeforeClose event not suffice? What are you trying to do?
 

huzman

New Member
Joined
Oct 2, 2003
Messages
29
Iridium, Thanks! This is what i am trying to to:

Private Sub App_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)

Worksheets(6).Visible = True
Worksheets(1).Visible = xlVeryHidden
Worksheets(2).Visible = xlVeryHidden
Worksheets(3).Visible = xlVeryHidden
Worksheets(4).Visible = xlVeryHidden
Worksheets(5).Visible = xlVeryHidden

Worksheets("Warning").Activate

Cells(1, 1).Activate
End Sub
 

Iridium

Well-known Member
Joined
Jul 15, 2002
Messages
2,831
So would this not suffice in the ThisWorkbook module (not in a standard module and assuming you have events enabled)?

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

Worksheets(6).Visible = True
    Worksheets(1).Visible = xlVeryHidden
    Worksheets(2).Visible = xlVeryHidden
    Worksheets(3).Visible = xlVeryHidden
    Worksheets(4).Visible = xlVeryHidden
    Worksheets(5).Visible = xlVeryHidden

    Worksheets("Warning").Activate

    Cells(1, 1).Activate
End Sub

HTH
 

huzman

New Member
Joined
Oct 2, 2003
Messages
29
Thanks again,
The issue with BeforeCloseEvent is that the code will run before the workbook closes.If the workbook has been changed, this event occurs before the user is asked to save changes.

While, with WorkbookBeforeClose Event, it happens immediately before any open workbook closes, and after the use is asked to save the changes, which is what i need.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,569
Messages
5,596,915
Members
414,110
Latest member
docops

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
Top