Macro functions on exit

G

grayday

I have a lot of workbook macros that hide toolbars and change othe
default settings on startup. It's annoying to close my program an
open up another excel document and have to restore all my settings. I
there a way to execute a set of functions with an OnClose call o
something?

I basically need to run a macro when they x-out of my program t
restore their settings.

Thanks in advance for any ideas
 
G

grayday

Thanks for the reply!

Seems like it certainly should work, but I keep getting this error:

Compile Error:

Procedure declaration does not match description of event or procedur
having the same name.

Here's my workbook page:

Private Sub Workbook_Open()
'

ActiveWindow.WindowState = xlNormal
With ActiveWindow
.Width = 540
.Height = 443.25
End With
With ActiveWindow
.Top = 24.25
.Left = 109.75
End With
With ActiveWindow
.DisplayHeadings = False
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
.DisplayWorkbookTabs = False
End With
Application.DisplayFormulaBar = False
Application.CommandBars("Standard").Visible = False
Application.CommandBars("Formatting").Visible = False


End Sub

Private Sub Workbook_BeforeClose()
'
Application.DisplayFormulaBar = True
Application.CommandBars("Standard").Visible = True
Application.CommandBars("Formatting").Visible = True

End Sub


I know the code is probably sloppy, I'm still learning and just use th
code from recorded macros a lot of the time.

If anyone can help with what I'm doing wrong, I would appreciate it .
 
J

JE McGimpsey

Event macro declarations must match the object model's description of
the procedure, including any arguments. In this case,
Workbook_BeforeClose() requires a boolean argument. You can get the
defaults by choosing the event procedure from the right-hand dropdown in
the ThisWorkbook module window. By default, the declaration should be

Private Sub Workbook_BeforeClose(Cancel As Boolean)

though the variable name need not be "Cancel":

Private Sub Workbook_BeforeClose(foo As Boolean)
 
Top