?
Solved

Problem getting started with MS Word/VBA in Visual Basic 5

Posted on 2003-03-25
3
Medium Priority
?
129 Views
Last Modified: 2010-05-01
Hello all,

I'm a novice VB programmer using VB5, and I'm trying to add MS Word capability to a basic database program that I've written. I've had some success with automating Excel, and figured that Word would essentially be the same task. However, for some reason, the program doesn't seem to cooperate. I originally wrote the program on a Win 2000 laptop with Office XP (the code is below), and it worked just fine. However, when I tried to use it on a Win XP Home desktop with Office XP (both of which all of our terminals at the office have), the program wouldn't work. Whenever it gets to the code about adding a new document, it crashes, saying that there is an Automation Error. Here is the code that I have been using:

Dim WrdApp As Object
Set WrdApp = CreateObject("Word.Application")
WrdApp.Documents.Add
WrdApp.Visible = True
Set WrdApp = Nothing

I've tried several other variations on this simple code, but it always seems to crash at the line where it adds a new document, or also even if I try to open an existing document. There may be something very simple that I'm missing, such as an incorrect reference or missing component...like I said, I am new at this. I have selected the Word 10.0 object library under components, but is there something else that I'm missing? If anyone could please let me know what might cause such an error, I'd definitely appreciate it. Thanks in advance for your help!

Danny Hammond
hammond@ku.edu
0
Comment
Question by:dhammond-ku
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 1000 total points
ID: 8208181
Try:

Dim WrdApp As Word.Application
Set WrdApp = New Word.Application
WrdApp.Documents.Add
WrdApp.Visible = True
Set WrdApp = Nothing

or

Dim WrdApp As Word.Application
Set WrdApp = CreateObject("Word.Application")WrdApp.Documents.Add
WrdApp.Visible = True
Set WrdApp = Nothing
0
 
LVL 18

Expert Comment

by:Sethi
ID: 8209209
If it is an automation error then it means that the client machine where you are trying to run your application doesn't have Microsoft Words installed. Even if you distribute your application with Words DLL's it wont run on a machine without Microsoft Words. Please check the version of Microsoft Words also if it is installed otherwise install Words and then run the application.
0
 

Expert Comment

by:CleanupPing
ID: 8899880
dhammond-ku:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question