473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 interoperoperat ability, where I declare objects as
follows:

Dim oWordApp As New Microsoft.Offic e.Interop.Word. Application, after adding
a reference to Microsoft.Offic e.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("W ord.Application ")
Dim docPath As String
Me.OpenFileDial og1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDial og1.ShowDialog( ) = DialogResult.OK Then
docPath = Me.OpenFileDial og1.FileName
End If
WordApp.Visible = True
'MsgBox("App Name = " & oWordApp.Name)
WordApp.Documen ts.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 2444
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("W ord.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.Applicatio n

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

Matt

"William LaMartin" <la******@tampa bay.rr.com> wrote in message
news:eS******** ******@tk2msftn gp13.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 interoperoperat ability, where I declare objects as
follows:

Dim oWordApp As New Microsoft.Offic e.Interop.Word. Application, after adding a reference to Microsoft.Offic e.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("W ord.Application ")
Dim docPath As String
Me.OpenFileDial og1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDial og1.ShowDialog( ) = DialogResult.OK Then
docPath = Me.OpenFileDial og1.FileName
End If
WordApp.Visible = True
'MsgBox("App Name = " & oWordApp.Name)
WordApp.Documen ts.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.Offic e.Interop.Word. In fact if I type dim oWordApp as
Word.Applicatio n, I get an error message to the effect that Word.Applicatio n
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******** ******@TK2MSFTN GP10.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("W ord.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.Applicatio n

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

Matt

"William LaMartin" <la******@tampa bay.rr.com> wrote in message
news:eS******** ******@tk2msftn gp13.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 interoperoperat ability, where I declare objects as follows:

Dim oWordApp As New Microsoft.Offic e.Interop.Word. Application, after adding
a reference to Microsoft.Offic e.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("W ord.Application ")
Dim docPath As String
Me.OpenFileDial og1.Filter = "Word files (*.doc)|*.doc"
If Me.OpenFileDial og1.ShowDialog( ) = DialogResult.OK Then
docPath = Me.OpenFileDial og1.FileName
End If
WordApp.Visible = True
'MsgBox("App Name = " & oWordApp.Name)
WordApp.Documen ts.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
2494
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 "Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, DCOM, and NT Services), because Office may exhibit unstable...
25
3729
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 machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of them, the user is getting an Automation Error. The code used is as follows: Dim objWord As...
12
5523
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 and office XP components installed. ie I have word/access/excel 2k/xp/2003 installed. I tried to do a usual access 2k to word 2k automation yet I get the error "Automation Error" "ClassFactory cannot supply requested class" when on late binding try...
17
6344
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
1835
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 Office Automation (Office 2003+). The .ASPX page is not part of a Web Forms Visual Studio project. It's just a stand-alone file. And therefore, there is not "References" setting or anything because there's no Visual Studio project. My...
3
2184
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! Thanks! -- - Mitchell Vincent - kBilling - Invoices Made Easy!
6
598
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 Excel.Range
9
39418
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 ticked for the application you want to Automate. Set up an application object variable to use (You can use With...End With if you prefer). Either : Use CreateObject(Class) to open a new object for multi-instance programs (For single Instance...
0
1385
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, we are using office 2003 and XP. I did not convert the database to 2003 since a few of our staff have laptops with windows 2000. I have quite a few functions/macros in MSAccess that outputs to ms
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.