ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro : switch between excel and word (https://www.excelbanter.com/excel-programming/317339-macro-switch-between-excel-word.html)

TOM

Macro : switch between excel and word
 
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

NickHK

Macro : switch between excel and word
 
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

"Tom" wrote in message
...
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

Macro : switch between excel and word
 
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.
WordApp.


Thx !
Tom



-----Original Message-----
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

"Tom" wrote in

message
...
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



.


NickHK

Macro : switch between excel and word
 
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


"Tom" wrote in message
...
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.
WordApp.


Thx !
Tom



-----Original Message-----
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

"Tom" wrote in

message
...
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

Macro : switch between excel and word
 
Set WordApp = GetObject(, "Word.Application")
works great

Many Thanks !!
Tom

-----Original Message-----
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


"Tom" wrote in

message
...
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.
WordApp.


Thx !
Tom



-----Original Message-----
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

"Tom" wrote in

message
...
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


.



.



All times are GMT +1. The time now is 02:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com