Programmatically open XLT for edit and stop macros

X

XP

Using Office 2003 and Windows XP;

I have a template file that I need to open for editing using automation
(late binding) and in doing so, I want to programmatically prevent macros
from firing. My code so far:

Dim oXL as Object
Dim oWB as Object
Dim sFullName = "fully qualified path to my file.xlt"
Set oXL = CreateObject("Excel.Application")
Set oWB = oXL.Workbooks.Open(sFullName)

Can someone please post example code and/or modify my code to achieve this?

Thanks much in advance.
 
T

Tom Ogilvy

Dim oXL as Object
Dim oWB as Object
Dim sFullName = "fully qualified path to my file.xlt"
Set oXL = CreateObject("Excel.Application")
oxl.EnableEvents = False
Set oWB = oXL.Workbooks.Open(FileName:=sFullName, _
Editable:=True)
 
P

Peter T

Hi Tom,

It's odd but that doesn't work for me with automation. Events are disabled
OK but then are re-enabled when opening the wb allowing the wb's Open event
to run.

Regards,
Peter T
 
T

Tom Ogilvy

That would be the case in xl2000 and earlier as I recall. In xl2002 and
later I believe it was fixed.

Are you using one of these earlier versions?
 
P

Peter T

That explains it, I was using XL2000.

FWIW, even in XL2000 disabling events within own instance does persist and
prevents a wb's open event firing, but not with automation.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top