Avoid document_New Event when opening a .DOT programmatically

P

Pony

Hi,
VBA-Code for nearly 300 .dots have to be changed. To avoid the
document-events when opening the .dots, I am using

myApplication.AutomationSecurity = msoAutomationSecurityForceDisable

The macro works well and my only problem is:
Is there any possibility to avoid the security-messages when opening and
saving the .dots. I don't want to press the Enter-Button 600 times.
Perhaps there is also another possibility to avoid the execution of then
document-events, I don't know?

Thanks
Gerlinde Kirse
 
J

Jonathan West

Pony said:
Hi,
VBA-Code for nearly 300 .dots have to be changed. To avoid the
document-events when opening the .dots, I am using

myApplication.AutomationSecurity = msoAutomationSecurityForceDisable

The macro works well and my only problem is:
Is there any possibility to avoid the security-messages when opening and
saving the .dots. I don't want to press the Enter-Button 600 times.
Perhaps there is also another possibility to avoid the execution of then
document-events, I don't know?

I think you may be out of luck. The security messages are there for the
specific purpose of making sure that code cannot change code without the
user's knowledge.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
P

Pony

Hello Jonathan,
I found another solution, that works well.
When I started writing the code I first tried to open the .DOTs as nomal
documents

Dim wdDok as word.Document
set wdDok = documents.open("C:\...\XXXX.DOT")

This code stopped with "Type-error". Therefore I thought I can't open the
Dots as a word-Document and tried another solution. But this solution wasn't
ok because of the security messages.

Now I tried the following code

Dim wdDok as word.Document
documents.open("C:\...\XXXX.DOT")
set wdDok = ActiveDocument

This code works well and I can do all the VBA-changes without any security
messages. Do you have any idea where is the difference using two lines
instead of one?? I tried it on two different installations.

regards
Gerlinde Kirse




Jonathan West said:
I think you may be out of luck. The security messages are there for the
specific purpose of making sure that code cannot change code without the
user's knowledge.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Hello Jonathan,
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?UG9ueQ==?=,

From my experience, the first code snippet ought to work. Are you certain you
declared wdDok as Word.Document and not as Word.Template? (Note, however, the
Document_New event won't fire in this case; it would be the Document_Open
event.)
When I started writing the code I first tried to open the .DOTs as nomal
documents

Dim wdDok as word.Document
set wdDok = documents.open("C:\...\XXXX.DOT")

This code stopped with "Type-error". Therefore I thought I can't open the
Dots as a word-Document and tried another solution. But this solution wasn't
ok because of the security messages.

Now I tried the following code

Dim wdDok as word.Document
documents.open("C:\...\XXXX.DOT")
set wdDok = ActiveDocument

This code works well and I can do all the VBA-changes without any security
messages. Do you have any idea where is the difference using two lines
instead of one?? I tried it on two different installations.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
P

Pony

I thought also, and therefore I was astonished of the "type error".

I tested it once more. dok is really declared as Document. The first snippet
doesn't work ( type error). The second snippet works without any problem and
the events are not fired.

First I tried declaring dok as object. The local-window showed me, that dok
was of type document, therefore I tried snippet 2 and was happy, that it
works.

I'm working with VBA since the earliest version. Sometimes you have to do
the unexspected. Nevertheless, my code works well. Perhaps my experience will
help other users.
thanks for your help.
 

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