View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default Workbook_BeforeClose

Not sure if this will help or not, but I use this kind of code when closing
my WB:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call 'yourmacronamehere'
End Sub

That works fine for me. All I can think of is put the important code in
another Sub...End Sub and then call that Sub.

Regards,
Ryan---
--
RyGuy


"Dave Unger" wrote:

Hello everyone,

I placed this post a few days ago, but my question remains
unaswered. This is a re-word of that post.

I have a large application that €śhides€ť Excel on startup (gridlines,
headings, visibility, etc), then restores everything on exit.
Everything works fine if closing the workbook manually, the problem
appears when trying to close via a procedure. The following is a
simplified example of the code.

Sub CloseMe()
ThisWorkbook.Close savechanges:=True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim wk As
Worksheet
Range("A1").Interior.ColorIndex = 4
Application.DisplayFormulaBar = True
ActiveWindow.DisplayGridlines = True
End Sub

If I step thru the code starting at CloseMe code, it steps thru to the
Workbook_BeforeClose procedure. There, the first line gets executed,
but nothing happens on the next two. Yet when I close the workbook
manually, it works as expected. Ive tried this on Xl97 & 2007, with
the same results.

I have to admit, this one caught me by surprise. I cant seem to find
anything regarding this in the groups/internet. Any advice would be
most appreciated.

Thanks for your help,

regards,

Dave U