COM Word 2000 Doc Protection

L

Lars

Hi,
I have a serious problem with Word 2000 and a COM-Addin. I'm using the
following code from VB 6:

oApp.ActiveDocument.Protect Word.wdAllowOnlyFormFields, bClear, sPassW
(oApp is the instance of Word.)

I have also tried oApp.ActiveDocument.Protect Word.wdAllowOnlyFormFields but
no difference.

When called the first time nothing happens, next call cause Word to crash!
The same code works perfectly when using Word 2003.

When using the COM Addin under Word 2000 I also tried to use the Protection
Dialog like this:
Set oDlg = oApp.Dialogs(wdDialogToolsProtectDocument)
oDlg.NoReset = bClear
oDlg.DocumentPassword = sPassW
oDlg.Execute
Set oDlg = Nothing

This code above protects the document but I can't set the protection type.
According to the help file the DialogToolsProtectDocument dialog should have
a property called 'Type', as in the function call. But, Type is a read only
property in the base dialog so the protection type can't be set using that
property. How can I protect a document for Forms in Word 2000 from a COM
Addin?

Thanks in advance
Lars-Eric
 
C

Cindy M -WordMVP-

Hi Lars,
I have a serious problem with Word 2000 and a COM-Addin. I'm using the
following code from VB 6:

oApp.ActiveDocument.Protect Word.wdAllowOnlyFormFields, bClear, sPassW
(oApp is the instance of Word.)

I have also tried oApp.ActiveDocument.Protect Word.wdAllowOnlyFormFields but
no difference.
Try using oApp instead of Word: oApp.wdAllowOnlyFormFields

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 :)
 
L

Lars

Cindy,

Thanks for your suggestion, but it didn't work. I even changed the parameter
to 2, which is what wdAllowOnlyFormFields is defined to.

It looks like the memory really gets scrued up as the error message that
pops up when Word craches tells that Word is trying to access memory at
adress 0x00000008 which is in the protected system area of the memory and no
application should have access to that area.

Seems like there is a bug in the automation interface of Word 2000, as the
same code works perfectly ok with Word 2003.

Calling the Tools/Protect dialog seems to work ok but then I don't know how
to set the protection type in the dialog. The documentation is erratic in
this case.

Regards,
Lars-Eric
 
L

Lars

Found a way to solve the problem!

Good old reliable WORDBASIC!!

oApp.WordBasic.ToolsProtectDocument DocumentPassword:=sPassW, _
NoReset:=bClear, Type:=2
did the trick.

Regards,
Lars-Eric
 

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