andreaspan
asked on
Call MSWORD from VB
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.Applica tion")
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
Method 1
--------------------------
Dim x As Object
Dim wb As Object
Dim ws As Object
Set x = CreateObject("Word.Applica
x.Visible = True
Set wb = x.Documents.Open("C:\Rents
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your code is fine as long as you have the reference. No solution required.
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.
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.
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?
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?
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.
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.
'Project' - 'References'.