By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,096 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Automation of Office programs

P: n/a
I have created a program that allows for the automation of things in Word
documents, like changing the values of DocVariables and the links to Excel
Sheets. I did it using interoperoperatability, where I declare objects as
follows:

Dim oWordApp As New Microsoft.Office.Interop.Word.Application, after adding
a reference to Microsoft.Office.Core and a reference to Microsoft Word. I
could do this since I have the Primary Interop Assemblies installed on my
computer. Everything works fine.

But I then realized that if I install this on a client's computer, in
addition to needing the .Net framework installed, they will also have to
have the Primary Interop Assemblies installed. I would like to avoid
having to install the PIAs , so I went back and tried to access Word the old
fashion way. After adding a Reference to Word, I put the following code in
a subroutine on the form.

Dim WordApp as object
WordApp = CreateObject("Word.Application")
Dim docPath As String
Me.OpenFileDialog1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then
docPath = Me.OpenFileDialog1.FileName
End If
WordApp.Visible = True
'MsgBox("App Name = " & oWordApp.Name)
WordApp.Documents.Open(docPath)

This code works, and the Word document is opened. But in writing the code
above, I had no autocompletion, and if I make the WordApp a shared object at
the form level, other subs on the form say that the document is not open
even though it is.

How do you get the above type of code to work as it did in Visual Basic?

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I think your problem with autocompletion is due to the way in which you are
declaring the word objects.

Dim WordApp as object
WordApp = CreateObject("Word.Application")

Since you are declaring WordApp as an object VB has no reference to what
type of object it actually is and cannot provide the properties/methods etc
that you are looking for. I've done similar Word automation and I think if
you change your declaration to this:

Dim mobjWordApp As Word.Application

you should gain access to the autocompletion functionality. Hope this
helps.

Matt

"William LaMartin" <la******@tampabay.rr.com> wrote in message
news:eS**************@tk2msftngp13.phx.gbl...
I have created a program that allows for the automation of things in Word
documents, like changing the values of DocVariables and the links to Excel
Sheets. I did it using interoperoperatability, where I declare objects as
follows:

Dim oWordApp As New Microsoft.Office.Interop.Word.Application, after adding a reference to Microsoft.Office.Core and a reference to Microsoft Word. I could do this since I have the Primary Interop Assemblies installed on my
computer. Everything works fine.

But I then realized that if I install this on a client's computer, in
addition to needing the .Net framework installed, they will also have to
have the Primary Interop Assemblies installed. I would like to avoid
having to install the PIAs , so I went back and tried to access Word the old fashion way. After adding a Reference to Word, I put the following code in a subroutine on the form.

Dim WordApp as object
WordApp = CreateObject("Word.Application")
Dim docPath As String
Me.OpenFileDialog1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then
docPath = Me.OpenFileDialog1.FileName
End If
WordApp.Visible = True
'MsgBox("App Name = " & oWordApp.Name)
WordApp.Documents.Open(docPath)

This code works, and the Word document is opened. But in writing the code
above, I had no autocompletion, and if I make the WordApp a shared object at the form level, other subs on the form say that the document is not open
even though it is.

How do you get the above type of code to work as it did in Visual Basic?

Nov 21 '05 #2

P: n/a
Even though I have added a reference to the Microsoft Word 11 Object
Library, when I type dim oWordApp as Word. there is no list of available
properties, etc. that pops up as there is when I type Dim oWordApp As New
Microsoft.Office.Interop.Word. In fact if I type dim oWordApp as
Word.Application, I get an error message to the effect that Word.Application
is not defined.

It is as if Visual Studio is forcing me to use the second method.
"Matthew Dill" <md***@ameritas.com> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
I think your problem with autocompletion is due to the way in which you are declaring the word objects.

Dim WordApp as object
WordApp = CreateObject("Word.Application")

Since you are declaring WordApp as an object VB has no reference to what
type of object it actually is and cannot provide the properties/methods etc that you are looking for. I've done similar Word automation and I think if you change your declaration to this:

Dim mobjWordApp As Word.Application

you should gain access to the autocompletion functionality. Hope this
helps.

Matt

"William LaMartin" <la******@tampabay.rr.com> wrote in message
news:eS**************@tk2msftngp13.phx.gbl...
I have created a program that allows for the automation of things in Word documents, like changing the values of DocVariables and the links to Excel Sheets. I did it using interoperoperatability, where I declare objects as follows:

Dim oWordApp As New Microsoft.Office.Interop.Word.Application, after adding
a reference to Microsoft.Office.Core and a reference to Microsoft Word.

I
could do this since I have the Primary Interop Assemblies installed on my computer. Everything works fine.

But I then realized that if I install this on a client's computer, in
addition to needing the .Net framework installed, they will also have to
have the Primary Interop Assemblies installed. I would like to avoid
having to install the PIAs , so I went back and tried to access Word the

old
fashion way. After adding a Reference to Word, I put the following code

in
a subroutine on the form.

Dim WordApp as object
WordApp = CreateObject("Word.Application")
Dim docPath As String
Me.OpenFileDialog1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then
docPath = Me.OpenFileDialog1.FileName
End If
WordApp.Visible = True
'MsgBox("App Name = " & oWordApp.Name)
WordApp.Documents.Open(docPath)

This code works, and the Word document is opened. But in writing the code above, I had no autocompletion, and if I make the WordApp a shared

object at
the form level, other subs on the form say that the document is not open
even though it is.

How do you get the above type of code to work as it did in Visual Basic?


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.