View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Check if Word is already active?

It's not working! And now I have TWO issues!

From the GetObject Help, I gleaned this:
On Error Resume Next
Set WD = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

I tried this with
Dim WD As Object
and
Dim WD As Word.Application

I stop with error on the GetObject line, which also means Resume Next is not
passing off to the next line. Why??!

The error message is "Active X component can't create object." I do have a
reference to the Word 9 library, and I'm running Word and Excel 2000.

Any suggestions?
Ed

"Tom Ogilvy" wrote in message
...
Look at the help on GetObject Try GetObject first.

--
Regards,
Tom Ogilvy


"Ed" wrote in message
...
I pulled up an Excel macro I wrote in my absolute newbie days (not that

I'm
too much farther down the road!) that opens a Word doc. It still works,

but
now I can see that it needs some tweaking. I use
Dim WD As Object
doc = Fpath & "\" & Fname & ".doc"
Set WD = CreateObject("Word.Application")
WD.Documents.Open doc
WD.Visible = True
Set WD = Nothing
(doc, Fpath, and Fname are all declared as well.)
Besides being late binding, this opens an entirely new instance of Word,
which can do some strange things to me, depending on what I'm doing in

Word
at the moment. What I'd really like to do is check to see if Word is
running first; if it is, then open the new doc within the current

instance -
if not, then open a new instance. What's the best way to check if Word

is
already running?

Ed