• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 132
  • Last Modified:

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

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
dhammond-ku
Asked:
dhammond-ku
1 Solution
 
Ryan ChongCommented:
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
 
SethiCommented:
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
 
CleanupPingCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now