472,790 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,790 software developers and data experts.

Automation of Office programs

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
2 2386
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jabailo | last post by:
I came across this article while researching a VB6 430 error: INFO: Considerations for Server-Side Automation of Office http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757 ...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
12
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
2
by: Alex Maghen | last post by:
Hi. I've seen several KBs on using .NET for MS Office Automation. But I have a particular question: I am developing a somewhat stand-alone .ASPX page which will need to do some relatively simple MS...
3
by: Mitchell Vincent | last post by:
Does anyone have some good examples of Excel automation with (VB).NET? I have some Excel spreadsheets that a customer needs parsed out but I've never tried to use Excel programatically before! ...
6
by: a.theil | last post by:
Please help! I need a simple excel automation, just 2 write some files into excel. I do: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As...
9
NeoPa
by: NeoPa | last post by:
In VBA (I expect VB would be similar) controlling another Office Application (Automation) can be done using the following steps : Ensure the Reference (VBA Window / Tools / References) has been...
0
by: Bullfrog | last post by:
My office application is really slow on Windows XP! First, some backgroud stuff. The MSAccess system that we use was developed while using Windows 2000, and Office 2000. At our new location,...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.