Newbie question - how can I run a macro on a protected document

G

Guest

Hi, I am using tcl with tcom to process some Word files, search for
keywords, etc. I need to run a macro to unlink some fields. How can
I run this macro and unprotect the document automagically if the
document is sent to me protected?

I can open the document and see the contents, but I cannot run
the macro.

Thanks for any help! This is the error I get:

::tcom::handle0x01439F60
% $::doc Run Macro1
0x80020003 {This method or property is not available because the document is
a p
rotected document.}
 
G

Graham Mayor

You will need to add the password if any between the quotes - then

Dim bProtected As Boolean
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""

End If

'Run your code

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

Thanks Graham! I assumed that the default password would be assumed to be ""
if it wasn't explicitly mentioned.

I added your code and it works now. i really appreciate the help.

Mayavi
 

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