Fail to access Interop.VBProject

A

Adam

I wanted to remove a VBA Form in a Word template via VB programming. The
following is the code. I have set the Word property of "Trust Access from
Visual Basic Project", but it seems that the VBProject object I got is
somehow invalid. Thanks in advance for any help!

Dim wordApp As Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document
Dim vbProj As Microsoft.Vbe.Interop.VBProject
Dim name As String

wordApp = New Microsoft.Office.Interop.Word.Application
doc = wordApp.Documents.Open(FileName:="C:\\Temp\\Test.dot")
vbProj = doc.VBProject
name = vbProj.Name //This line throws exception
 
C

Cindy M.

Hi Adam,

FWIW it works for me (using C#, no less, which is usually more a problem).
What's the exact wording of the error message you get (with your code in a
Try...Catch block!)?

The VBA project isn't protected, by any chance?
I wanted to remove a VBA Form in a Word template via VB programming. The
following is the code. I have set the Word property of "Trust Access from
Visual Basic Project", but it seems that the VBProject object I got is
somehow invalid. Thanks in advance for any help!

Dim wordApp As Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document
Dim vbProj As Microsoft.Vbe.Interop.VBProject
Dim name As String

wordApp = New Microsoft.Office.Interop.Word.Application
doc = wordApp.Documents.Open(FileName:="C:\\Temp\\Test.dot")
vbProj = doc.VBProject
name = vbProj.Name //This line throws exception

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 

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