Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel to Word Macro | Excel Discussion (Misc queries) | |||
Macro switch between windows question | Excel Discussion (Misc queries) | |||
passing arguments from an excel macro to a word macro | Excel Discussion (Misc queries) | |||
Macro - Open Word with Excel macro | Excel Discussion (Misc queries) | |||
Using Word and Excel in one Macro | Excel Programming |