Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Call MSWORD from VB

Posted on 1999-01-20
6
Medium Priority
?
176 Views
Last Modified: 2008-03-04
Iam using VB 5.0. I want to open winword application from VB and a specific DOC file. I used the following method but it doesn't work:

Method 1
---------------------------
Dim x As Object
Dim wb As Object
Dim ws As Object

Set x = CreateObject("Word.Application")
x.Visible = True
Set wb = x.Documents.Open("C:\Rents\MailMerge.doc")
Set ws = wb.Documents(1)

=============================================

Method 2
--------------
Dim ms As Object
Dim sfilename As String

   Set ms = CreateObject("Word.basic")
   sfilename = "C:\RENTS\MailMerge.Doc" 'CurDir + "\FindPaymentsForCheck.RPT"
   ms.fileopen sfilename


Regards
Andreas
0
Comment
Question by:andreaspan
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:sduckett
ID: 1469560
Have you added a reference to the Word 8.0 object library?
'Project' - 'References'.
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 300 total points
ID: 1469561
Please look at the following Previously Answered Question:

http://www.experts-exchange.com/topics/comp/lang/visualbasic/Q.10116990

If this question gives you enough information to do what you want, you can reject this answer and delete this question - I don't want to be taking points from you twice!
0
 
LVL 3

Expert Comment

by:sduckett
ID: 1469562
Your code is fine as long as you have the reference. No solution required.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:caraf_g
ID: 1469563
Including a reference is problematic as far as applications such as Word are concerned: you're basically forcing your user to use one particular version of Word.

In your Method 2 you're working around this problem by using CreateObject - one of the few situations where CreateObject is preferable over adding a Reference to your Project and using the New keyword. In general, CreateObject is slower and should be avoided but not in this case.

So your Method 2 is getting close to the right solution but if you look at the PAQ mentioned in my answer you can get it cheap.
0
 
LVL 3

Expert Comment

by:sduckett
ID: 1469564
caraf_g:
Your right the reference isn't completely necessary as the code works fine without it (My false assumption, Sorry).
But if the code works fine in my test app, why was the question asked? You've appraised both solutions as if they are working haven't you?
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1469565
Hello Andreas,

Thank you for the 305 points but I didn't expect you to give me that much - I pointed you at the PAQ so you could buy that for 5 points and save the other points by rejecting my answer to this question.

But thanks anyway.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

886 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