Macro : switch between excel and word

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hi,

I'm using this macro :

Range("A1").Select
Selection.Copy

Const wdAlignParagraphCenter = 1

Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
.Documents.Add

With .Selection
.Paste
.ParagraphFormat.Alignment =
wdAlignParagraphCenter
.PageSetup.TopMargin = 36

End With


End With
Sheets("Quotation").Select

Now I want to make a new macro that does the same, but
not opens Word but switches to word when it is already
open. (it has to create a new doc in word that is already
open)

Is this possible ?
How can I do this ?

Thx in advance!
Tom
 
Tom,
If it is your instance of Word created before, pass your reference e.g.
WordApp.
If you want any instance of Word that happens to be running, use GetObject.

NickHK
 
NickHK

If I change : Set WordApp = CreateObject
("Word.Application") into
Set WordApp = GetObject("Word.Application")
and run the marco when word is already open, it doens't
work.

what do you mean with : pass your reference e.g.

Thx !
Tom
 
Tom,
Read the help on GetObject
Hint: Set WordApp = GetObject(, "Word.Application")

If you creating your own instance of Word you will have
Set WordApp = CreateObject ("Word.Application")

You can then pass/use WordApp in other code outside of your initial routine,
if the object variable is defined with sufficient scope e.g. in a .bas.
When you finished all your processing in various routines, close/quit Word
and finally set your WordApp to nothing.

NickHK
 
Back
Top