PC Review


Reply
Thread Tools Rate Thread

Automation of Office programs

 
 
William LaMartin
Guest
Posts: n/a
 
      18th Aug 2004
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?



 
Reply With Quote
 
 
 
 
Matthew Dill
Guest
Posts: n/a
 
      18th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>
>



 
Reply With Quote
 
William LaMartin
Guest
Posts: n/a
 
      18th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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?
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to start Office application in Automation mode via Office itself? HemiltonChen@hotmail.com Microsoft Excel Programming 0 23rd Jan 2008 07:21 AM
Office automation application which will work with any version of office C#.NET Silly Programmer Microsoft Excel Programming 1 21st Feb 2004 10:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:45 PM.