Workbook_BeforeClose event

Charles Bushby

New Member
Joined
Aug 10, 2005
Messages
42
When I open an excel file the workbook open event runs code to disable cut, copy and paste and hides the formula bar. When the file is closed I wish to enable cut, copy and paste and show the formula bar. I have tried the following code but it doesn't work. Does anyone know how to write code to make it work?

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Cancel = True Then
Call EnableCutAndPaste
Application.DisplayFormulaBar = True
ElseIf Cancel = False Then
Call DisableCutAndPaste
Application.DisplayFormulaBar = False
End If
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I think you have the Cancel thingy te other way around :)

Should be like this :

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Cancel = False Then
Call EnableCutAndPaste
Application.DisplayFormulaBar = True
ElseIf Cancel = True Then
Call DisableCutAndPaste
Application.DisplayFormulaBar = False
End If
End Sub

Regards.
 
Upvote 0
I'd think about putting that in the Workbook_Deactivate code, so that I could have another workbook open at the same time as the disabled one.
 
Upvote 0

Forum statistics

Threads
1,215,648
Messages
6,126,007
Members
449,280
Latest member
Miahr

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