Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Run Word macro from VBscript - If it exists

goldyr (Programmer) (OP)
13 Oct 05 7:31
I have a VBScript that creates a new document from a teplate (.dot) and inserts data from another application. When the data has been inserted I want to run the macro that protects the document(allow only forms). It is working when the macro exists in the wordtemplate. If I want to open another template I get an error message because the macro does not exist. How can I make the script to run only if the macro exists in the word template? My code for running macro:
WordApp.Run("ProtectDocument")
mrmovie (TechnicalUser)
13 Oct 05 8:10
i cant answer your question exactly i am afraid but you could try...

wrap the

WordApp.Run("ProtectDocument")

in an On Error Resume Next and catch the error?
not the same as a If WordApp.MacroExists(...) but might do what you want?

alternatively how about putting the code from "ProtectDocument" into your script so you dont have to worry about what the .dot file contains. might make maintence easier?

you will prob find the VBA forum might get you better results.
good luck
goldyr (Programmer) (OP)
13 Oct 05 8:40
Yes this works. Thanks!

On Error Resume Next
    WordApp.Run("ProtectDocument")
   On Error Goto 0

If I put the code in the script I still have the problem with other documents that I don't want to protect. i us the same script for all documents.
mrmovie (TechnicalUser)
13 Oct 05 8:48
fair point, could you use naming convention for the .dot file _p in the name for ones you want to protect? silly idea maybe.
goldyr (Programmer) (OP)
13 Oct 05 8:53
Yes maybe, can you help me with the code?

The macro says:
ActiveDocument.Protect Password:="",NoReset:=False,Type:= _
        wdAllowOnlyFormFields

How do I write it in VBCScript??
The document name is "Kvalitet Bedömning prod.dot"
PHV (MIS)
13 Oct 05 8:59
WordApp.Documents("Kvalitet Bedömning prod.dot").Protect 2, False, "" ' 2=wdAllowOnlyFormFields

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886

tsuji (TechnicalUser)
13 Oct 05 8:59
>ActiveDocument.Protect Password:="",NoReset:=False,Type:= _
        wdAllowOnlyFormFields

ActiveDocument.Protect 2,False,""

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close