Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DKS DKS is offline
external usenet poster
 
Posts: 103
Default Worksheet CLOSE related macros

Hi,

When a user does a CLOSE of a worksheet, I want to run certain macros. I
can capture the event of closing the workset. So no sweat there.

But in my macro, I want to take certain actions depending on whether the
worksheet is yet to be saved (Yes or No). Meaning, if there are no changes
to be saved then I want to exit the macro; otherwise I want to run the macro.

Other than using a public boolean field that maintains a status on is the
worksheet changed, is there any other way I can get excel to give me this
information?

Many thanks in anticipation.

(AB123).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Worksheet CLOSE related macros

Hi,


If ThisWorkbook.Saved Then
'Do Nothing
Else
Call MyMacro
End If

Mike

"DKS" wrote:

Hi,

When a user does a CLOSE of a worksheet, I want to run certain macros. I
can capture the event of closing the workset. So no sweat there.

But in my macro, I want to take certain actions depending on whether the
worksheet is yet to be saved (Yes or No). Meaning, if there are no changes
to be saved then I want to exit the macro; otherwise I want to run the macro.

Other than using a public boolean field that maintains a status on is the
worksheet changed, is there any other way I can get excel to give me this
information?

Many thanks in anticipation.

(AB123).

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Worksheet CLOSE related macros

From VBE left treeview search for the workbook name and click on + to expand
it. Within that you should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

End Sub

On sheet activate you can get the key fields to a public variable and check
out this during close..to see whether these fields have changed..

If this post helps click Yes
---------------
Jacob Skaria


"DKS" wrote:

Hi,

When a user does a CLOSE of a worksheet, I want to run certain macros. I
can capture the event of closing the workset. So no sweat there.

But in my macro, I want to take certain actions depending on whether the
worksheet is yet to be saved (Yes or No). Meaning, if there are no changes
to be saved then I want to exit the macro; otherwise I want to run the macro.

Other than using a public boolean field that maintains a status on is the
worksheet changed, is there any other way I can get excel to give me this
information?

Many thanks in anticipation.

(AB123).

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Worksheet CLOSE related macros

Oops..misread your query...Please ignore..

"Jacob Skaria" wrote:

From VBE left treeview search for the workbook name and click on + to expand
it. Within that you should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

End Sub

On sheet activate you can get the key fields to a public variable and check
out this during close..to see whether these fields have changed..

If this post helps click Yes
---------------
Jacob Skaria


"DKS" wrote:

Hi,

When a user does a CLOSE of a worksheet, I want to run certain macros. I
can capture the event of closing the workset. So no sweat there.

But in my macro, I want to take certain actions depending on whether the
worksheet is yet to be saved (Yes or No). Meaning, if there are no changes
to be saved then I want to exit the macro; otherwise I want to run the macro.

Other than using a public boolean field that maintains a status on is the
worksheet changed, is there any other way I can get excel to give me this
information?

Many thanks in anticipation.

(AB123).

  #5   Report Post  
Posted to microsoft.public.excel.programming
DKS DKS is offline
external usenet poster
 
Posts: 103
Default Worksheet CLOSE related macros

Thanks Mike, this is exactly what I was looking for.

Jacob: thanks for your reply, but I preferred to work without public
variables and so I preferred Mike's solution.

"Mike H" wrote:

Hi,


If ThisWorkbook.Saved Then
'Do Nothing
Else
Call MyMacro
End If

Mike

"DKS" wrote:

Hi,

When a user does a CLOSE of a worksheet, I want to run certain macros. I
can capture the event of closing the workset. So no sweat there.

But in my macro, I want to take certain actions depending on whether the
worksheet is yet to be saved (Yes or No). Meaning, if there are no changes
to be saved then I want to exit the macro; otherwise I want to run the macro.

Other than using a public boolean field that maintains a status on is the
worksheet changed, is there any other way I can get excel to give me this
information?

Many thanks in anticipation.

(AB123).

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
How to run macros as one close a excel? Hashmi Excel Programming 2 January 13th 09 12:06 PM
close WB after clicking DISABLE MACROS Mario M Excel Programming 1 July 26th 05 12:51 PM
Extend Rows and related formula downwards using functions not macros NewRipper New Users to Excel 0 June 27th 05 08:32 PM
Search a worksheet and add related cells izbryte Excel Worksheet Functions 1 November 22nd 04 09:57 PM
Excel crashes on close - macro related Bert[_3_] Excel Programming 0 July 23rd 04 01:56 PM


All times are GMT +1. The time now is 12:21 AM.

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

About Us

"It's about Microsoft Excel"