Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default 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



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default 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


.



.

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
Excel to Word Macro Liz J[_2_] Excel Discussion (Misc queries) 1 December 2nd 09 08:27 PM
Macro switch between windows question punter Excel Discussion (Misc queries) 3 June 21st 06 06:11 PM
passing arguments from an excel macro to a word macro KWE39 Excel Discussion (Misc queries) 1 July 7th 05 03:56 PM
Macro - Open Word with Excel macro Bill Excel Discussion (Misc queries) 3 May 23rd 05 11:21 PM
Using Word and Excel in one Macro Ian Belcher[_2_] Excel Programming 2 October 26th 03 01:14 AM


All times are GMT +1. The time now is 09:44 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"