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!!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Would the Workbook_BeforeClose event not suffice? What are you trying to do?
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,580
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