Error: Programmatic Access is not trusted

R

Rhino

I am revisiting an old VBScript that I wrote several years ago. It basically
opens an existing Word document, then exports the macros associated with
that document.

This is the script:

===========================
' Get arguments into variables
If WScript.Arguments.Count < 1 Then
MsgBox "Too few arguments; expecting one."
WScript.Quit
Elseif WScript.Arguments.Count > 1 then
MsgBox "Too many arguments; expecting one."
WScript.Quit
Else
strArg1 = WScript.Arguments.Item(0)
End If

' Find path for MyDocuments folder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(&H5&)
strMyDocPath = objFolder.Self.Path

' Start Word Application, open resume.doc in MyDocuments
Set oWd = CreateObject("Word.Application")
oWd.Visible = False
Set oDoc = oWd.Documents.Open(strMyDocPath & "\rhino-resume.doc")

'Run macro named exportMacros, which has one argument
retcde = oWd.Run("exportMacros",strArg1)

'Save changes to doc on closing and quit Word
oDoc.Save
oDoc.Close
oWd.Quit
Set oWd = Nothing

Set objShell = Nothing

WScript.quit(retcde)
===========================

When I execute the script, I get a message dialog that says:

==================
Microsoft Visual Basic

Run-time error '6068':

Programmatic access to Visual Basic Project is not trusted.

[Continue] [End] [Debug] [Help]
===================

The "Continue" button is greyed out which is unfortunate, because that's the
one I'd like to press....

I don't remember seeing this error when I ran the script in the past but I
was running Word 2002 at the time. I strongly suspect that something changed
in Word 2007 to increase security....

Anyway, what do I do to satisfy the script that I want to run the
exportMacros macro and that I trust the code that I am running?

Also, just in case further problems arise, can someone advise me where to
find detailed documentation on Visual Basic runtime errors?

I'm an experienced programmer but have VERY little experience with Visual
Basic; I'm mostly a Java guy!

I'm running Windows XP SP2.
 
B

broro183

hi Rhino
Perhaps...

Press the big button at the top left - Word Options - Trust Center -
Trust Center Settings - tick "Trust access to..."

hth
Rob
 
R

Rhino

broro183 said:
hi Rhino
Perhaps...

Press the big button at the top left - Word Options - Trust Center -
Trust Center Settings - tick "Trust access to..."
I'll bet that seemed obvious to you but it certainly wasn't to me: I'd never
heard of the Trust Center before :) I've just had Word 2007 for a few days
and am still getting on to it. Thanks, that solved the problem!

However, it simply revealed a new problem. But this looks more like a macro
problem than a VB one so I'll ask about it elsewhere.

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