Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Prevent code running

Is there any way I can prevent the 'Workbook_BeforeClose' code module
running at the point where I have inserted the asterisks

Sub NewName()

Application.ScreenUpdating = False
Application.EnableEvents = False

'other code

ThisWorkbook.SaveCopyAs filename:="C:\Users\Sandy\Documents\NewBook.xls"

ThisWorkbook.Close SaveChanges:=False

************

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Thanks
Sandy

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Prevent code running

Sorry got the pasting wrong

If I do this

Sub NewName()

Application.ScreenUpdating = False
Application.EnableEvents = False

'other code

ThisWorkbook.SaveCopyAs filename:="C:\Users\Sandy\Documents\NewBook.xls"

ThisWorkbook.Close SaveChanges:=False

************

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

then the Before_Close does not run but the EnableEvents and ScreenUpdating
remain false next time the application is opened.

And if I do this

Sub NewName()

Application.ScreenUpdating = False
Application.EnableEvents = False

'other code

ThisWorkbook.SaveCopyAs filename:="C:\Users\Sandy\Documents\NewBook.xls"

Application.ScreenUpdating = True
Application.EnableEvents = True

ThisWorkbook.Close SaveChanges:=False

************


End Sub

then the Before_Close runs.

Hope this makes sense
Sandy



"Sandy" wrote in message
...
Is there any way I can prevent the 'Workbook_BeforeClose' code module
running at the point where I have inserted the asterisks

Sub NewName()

Application.ScreenUpdating = False
Application.EnableEvents = False

'other code

ThisWorkbook.SaveCopyAs
filename:="C:\Users\Sandy\Documents\NewBook.xls"

ThisWorkbook.Close SaveChanges:=False

************

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Thanks
Sandy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Prevent code running

That is because you are saving your file with the updating and events off...
just turn them back on **before** you do the save.

Sub NewName()

Application.ScreenUpdating = False
Application.EnableEvents = False

'other code

Application.ScreenUpdating = True
Application.EnableEvents = True

ThisWorkbook.SaveCopyAs Filename:="C:\Users\Sandy\Documents\NewBook.xls"

ThisWorkbook.Close SaveChanges:=False

End Sub

Rick


"Sandy" wrote in message
...
Sorry got the pasting wrong

If I do this

Sub NewName()

Application.ScreenUpdating = False
Application.EnableEvents = False

'other code

ThisWorkbook.SaveCopyAs
filename:="C:\Users\Sandy\Documents\NewBook.xls"

ThisWorkbook.Close SaveChanges:=False

************

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

then the Before_Close does not run but the EnableEvents and ScreenUpdating
remain false next time the application is opened.

And if I do this

Sub NewName()

Application.ScreenUpdating = False
Application.EnableEvents = False

'other code

ThisWorkbook.SaveCopyAs
filename:="C:\Users\Sandy\Documents\NewBook.xls"

Application.ScreenUpdating = True
Application.EnableEvents = True

ThisWorkbook.Close SaveChanges:=False

************


End Sub

then the Before_Close runs.

Hope this makes sense
Sandy



"Sandy" wrote in message
...
Is there any way I can prevent the 'Workbook_BeforeClose' code module
running at the point where I have inserted the asterisks

Sub NewName()

Application.ScreenUpdating = False
Application.EnableEvents = False

'other code

ThisWorkbook.SaveCopyAs
filename:="C:\Users\Sandy\Documents\NewBook.xls"

ThisWorkbook.Close SaveChanges:=False

************

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Thanks
Sandy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Prevent code running

Anytime you need to prevent code, be it in an event or not, from running in
particularcirumstances, you can do this by:

1, Create a Boolean Public variable, say bWatchSandyRun
2. Set the value to vbTRue or vbFalse,as needed.
3. With the code block, be itt event code or not, test the bWatchSandyRun to
detertmine when code should run.


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 prevent vba code from running? kfng Excel Programming 3 November 17th 07 12:48 PM
hide/protext auto_open code so user can't prevent it from running Scott Excel Programming 4 May 18th 07 04:40 PM
how to prevent code running when in a worksheet code Corey Excel Programming 5 August 13th 06 08:52 AM
Prevent code in "Sheet Activate" from running when sheet made visible from other macr Simon Lloyd[_794_] Excel Programming 10 June 21st 06 09:15 AM
Prevent others from running my macros Frederick Chow Excel Programming 2 December 13th 05 06:02 PM


All times are GMT +1. The time now is 04:29 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"