Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

runtime error 48 with createobject("word.application") 1

Status
Not open for further replies.

jlsmithhartfiel

Programmer
Jan 7, 2002
336
US
I'm trying to perform a mail merge with word and have found several examples here and on Microsoft's site. My problem is I'm getting a run-time error '48' when trying to run this basic code.
Code:
Option Explicit
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document

Private Sub command1_click()
  Dim wrdSelection As Word.Selection
  Dim wrdMailMerge As Word.MailMerge
  Dim wrdMergeFields As Word.MailMergeFields
  
  Dim StrToAdd As String
  
  'create an instance of word and make it visible
  [COLOR=#ff0000]Set wrdApp = CreateObject("Word.Application")[/color]
  wrdApp.Visible = True
End Sub

The line in red is what kicks up the error. I'm not sure what to look at. Any ideas?

I'm using VB6 sp4 and Word 2000. I've added the reference to Word 9.0 library to my project. Hope this helps,
Jessica
[ponytails2]
 
The CreateObject() method is rather outdated. You're going to have better luck with the modern technique:

Code:
Set wrdApp = New Word.Application


VBSlammer
redinvader3walking.gif
 
Thank you VBslammer. I've tried that as well, with the same response. Hope this helps,
Jessica
[ponytails2]
 
Your code runs fine on my box. If you are getting Runtime Error 48 then your Microsoft Word type library is either corrupted, missing or an incompatible version.

I'm using Office 2000 and my Word Library file is:
Code:
FILE:    C:\Program Files\Microsoft Office\Office\MSWORD9.OLB
SIZE:    536K
DATE:    3/17/1999
VERSION: 9.0.0.2717

Have you tried to run your program on a different machine?

VBSlammer
redinvader3walking.gif
 
You might try updating VB to SP5:
Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Well, no luck so far. :(

I've tried:
installing sp5 for vb6
copying the olb file from a pc that is working

Only mine and one other in the office is not working. Everyone else is fine. Hope this helps,
Jessica
[ponytails2]
 
The first thing that happens when you use CreateObject is a lookup for a registry key in:

HKEY_CLASSES_ROOT\<ObjectClass>

or in this case:

HKEY_CLASSES_ROOT\Word.Application.9

On my system the GUID for this class is:

{000209FF-0000-0000-C000-000000000046}

Check yours and see if it is different on each of the machines your code is working on.
VBSlammer
redinvader3walking.gif
 
Have you tried:
Code:
CreateObject(&quot;Word.Application.9&quot;)
VBSlammer
redinvader3walking.gif
 
Thanks for your help VBSlammer! Unfortunately the registry entries look identical and the word.application.9 gives the same result. I've tried running Office repair - maybe I should try uninstalling & reinstalling Office. Hope this helps,
Jessica
[ponytails2]
 
You should also have a registry entry for:

HKEY_CLASSES_ROOT\Word.Application

with subkeys of:

\CurVer
\CLSID

Make sure the CurVer is &quot;Word.Appication.9&quot; and the \CSLID is the same as the CLSID for Word 2000.
VBSlammer
redinvader3walking.gif
 
>The CreateObject() method is rather outdated

I'd love to hear the explanation of this statement...
 
OK, it was 4:00 in the morning and my choice of words was a littly hazy. CreateObject() has been around for a while and all the documentation for it is rather old.

The debate against CreateObject is usually centered around early versus late-binding. CreateObject has excellent compatibility for instances when the object to create is unknown at design-time.

However, if the object is known and early-bound such as we're talking about here, the New operator uses a more efficient internal COM process than CreateObject's external COM process.

The drawback is that the New operator requires the object to be of a specific type and even a version difference can affect it in some cases.

How's that.
VBSlammer
redinvader3walking.gif
 
VTBLs versus IDispatch, you mean...

>The debate against CreateObject is usually centered around early versus late-binding

Mistakenly. CreateObject has little to do with whether an object is early or late bound. That depends on how the object is declared:
[tt]
dim myWord as Word.Application
set myWord = New Word.Application
[/tt]
and
[tt]
dim myWord as Word.Application
set myWord = CreateObject(&quot;Word.Application&quot;)
[/tt]
are both examples of early binding. CreateObject is, however, slightly slower at instantiating the object since it has to load all the type information from Registry.

 
Thanks for all your help VBSlammer. Unfortunately I can't get this to work - I know it's something to do with my particular pc & it's communication between word & VB. I have a workaround though - our software was written in a different language & the original author didn't know how to talk to word, so we were using a vb dll. I've since figured out how to integrate word, so I'm in business.

Thanks again! Hope this helps,
Jessica
[ponytails2]
 
[soapbox]When I said:

The debate against CreateObject is usually centered around early versus late-binding...

I guess I should have been more explicit:

The debate against CreateObject is usually centered around when to use it. If the object is unknown or late-bound - use CreateObject. If the object is known or early-bound - use New.

I didn't say CreateObject determined binding, only that the debate concerning its use centered on binding.

HTH

VBSlammer
redinvader3walking.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top