View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Zack Barresse Zack Barresse is offline
external usenet poster
 
Posts: 124
Default Edit VBA Code without opening the workbook

Not really sure what you mean. If you were having problems with a
workbook_open event firing upon opening it via code, turning off the events
will not trigger it, thus no recursive loop. Take this for example...

Sub RunMeNow()
Call ToggleEvents(False)
Workbooks.Open ThisWorkbook.Path & "\Book1.xls"
Call ToggleEvents(True)
End Sub

Public Sub ToggleEvents(ByVal blnState As Boolean)
'Originally written by firefytr
With Application
.DisplayAlerts = blnState
.EnableEvents = blnState
.ScreenUpdating = blnState
If blnState Then .CutCopyMode = False
If blnState Then .StatusBar = False
End With
End Sub

Opening that particular workbook with the sub routine toggling the events
off will not fire the workbook_open event in the target workbook. So if you
want to supress that event, just toggle the EnableEvents property to false.
No need to disable macros. Unless you are manually opening the workbook,
then I may have mistaken your question in its origin.

HTH

--
Zack Barresse



"pwrichcreek" wrote in message
...
Thanks for your reply Zack, but it doesn't address the problem I am (was)
having. My problem was not a matter of trying to optimize the code; rather
it
had a recursive bug and I was unable to open the workbook without the code
going into a never-ending loop.

Phil

"Zack Barresse" wrote:

Hi there,

Try taking a look at the EnableEvents property. I use something like
this
to call before/after running code to optimize it slightly...

Public Sub ToggleEvents(ByVal blnState As Boolean)
'Originally written by firefytr
With Application
.DisplayAlerts = blnState
.EnableEvents = blnState
.ScreenUpdating = blnState
If blnState Then .CutCopyMode = False
If blnState Then .StatusBar = False
End With
End Sub

HTH

--
Zack Barresse



"pwrichcreek" wrote in message
...
I have VBA event code in an EXCEL workbook that goes into a never-ending
loop. I know what the problem is -- it triggers its own event! -- but I
don't
know how to edit the errant code without opening the workbook. Is there
a
way
to edit the code without opening the workbook?

TIA,

Phil