Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   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?

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


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 27,285
Default Check if Word is already active?

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




  #3   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?

Thanks, Tom. That got it for me.
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






  #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






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
check active cell column KimR.Hammel[_2_] Excel Programming 2 August 10th 05 09:35 PM
Check if Active Workbook is Empty scantor145[_18_] Excel Programming 1 July 26th 05 03:21 PM
Macro to copy cell data to word document based on an active row? Brian Excel Programming 2 September 16th 04 01:55 PM
Check active sheet not the one with macros Oscar Excel Programming 2 July 30th 04 04:32 PM
Code to check for active worksheet KimberlyC Excel Programming 2 November 5th 03 02:49 AM


All times are GMT +1. The time now is 04:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"