Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Excel closing file problem

Hi

I have some code in the "Thisworkbook"

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim lastsheet As Long
lastsheet = Sheets.Count
For N = 2 To lastsheet
Sheets(N).Visible = False
Next
Me.Save
Me.Close

End Sub

This should hide , save and close the workbook once it has been closed.
Sometimes when the workbook is closed excel does not execute this code
and mearly just ask if you want to save and then just closes the
workbook without hiding the sheets.

Is there something I need to change in my code?

Thanks

John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Excel closing file problem

First, I'd remove the me.close line. That's gonna happen already.

Second, I couldn't break your code to do what you experienced.

Third, I've always found it better to put this kind of stuff in the
workbook_open event. That way, the workbook doesn't have to be saved by the
user.

If they open the workbook, really screw it up, your code will save it when they
close the workbook. Maybe not what you or the user wants.



Woody1313 wrote:

Hi

I have some code in the "Thisworkbook"

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim lastsheet As Long
lastsheet = Sheets.Count
For N = 2 To lastsheet
Sheets(N).Visible = False
Next
Me.Save
Me.Close

End Sub

This should hide , save and close the workbook once it has been closed.
Sometimes when the workbook is closed excel does not execute this code
and mearly just ask if you want to save and then just closes the
workbook without hiding the sheets.

Is there something I need to change in my code?

Thanks

John


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem when closing Excel 2007 and with Add-ins Gary Excel Discussion (Misc queries) 1 January 4th 08 01:02 AM
Problem closing Excel David Excel Discussion (Misc queries) 2 January 29th 06 01:02 AM
Problem Closing Excel m.ahrens Excel Programming 0 February 24th 05 10:37 AM
Problem closing Excel Jim Simpson Excel Programming 2 May 29th 04 06:25 PM
Excel Closing Problem Him_B Excel Programming 4 January 19th 04 07:16 AM


All times are GMT +1. The time now is 06:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"