ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   select all & copy in word from macro in excel (https://www.excelbanter.com/excel-programming/301895-select-all-copy-word-macro-excel.html)

fitful_thought

select all & copy in word from macro in excel
 
Hello,
I'm using excel to create a new document in word.
When the word document is created I would like to select all and copy.
Can I do this from the excel macro?
Many thanks in advance for any help,

--
Regards,
Lindstrom



Kilo Bravo

select all & copy in word from macro in excel
 
sure, you'll have to check the Microsoft Word Object Library. Then you can
use all the word VBA objects in your module in excel.

--
KB

If A equals success, then the formula is: A = X + Y + Z, X is work. Y is
play. Z is keep your mouth shut.
--Albert Einstein

"fitful_thought" wrote in message
...
Hello,
I'm using excel to create a new document in word.
When the word document is created I would like to select all and copy.
Can I do this from the excel macro?
Many thanks in advance for any help,

--
Regards,
Lindstrom





SAMURA

select all & copy in word from macro in excel
 
Hi. Then you can use "OLE Automation". How about trying this macro?


Sub CopyFromWord()

Dim wordApp As Object
Dim wordDoc As Object

'started the Word
Set wordApp = CreateObject("Word.Application")

With wordApp
.Visible = True
.WindowState = wdWindowStateNormal
.Documents.Add
Set wordDoc = .ActiveDocument
End With

'inserted arbitrary text (is able to omit)
With wordApp.Selection
.InsertAfter "Created time: "
.InsertAfter Now()
End With

'[Select All] and [Copy]
With wordApp.Selection
.WholeStory
.Copy
End With

'pasted to this worksheet "sheet1"
ThisWorkbook.Sheets("sheet1").Range("A1").PasteSpe cial xlPasteValues

'saved word document
wordDoc.SaveAs "test.doc"
wordDoc.Close

'quitted the Word
wordApp.Quit
Set wordDoc = Nothing
Set wordApp = Nothing

End Sub


SAMURA



"fitful_thought" wrote in message
...
Hello,
I'm using excel to create a new document in word.
When the word document is created I would like to select all and copy.
Can I do this from the excel macro?




fitful_thought

select all & copy in word from macro in excel
 
Arigato Samura,
--
Regards,
Lindstrom

"SAMURA" wrote in message
...
Hi. Then you can use "OLE Automation". How about trying this macro?


Sub CopyFromWord()

Dim wordApp As Object
Dim wordDoc As Object

'started the Word
Set wordApp = CreateObject("Word.Application")

With wordApp
.Visible = True
.WindowState = wdWindowStateNormal
.Documents.Add
Set wordDoc = .ActiveDocument
End With

'inserted arbitrary text (is able to omit)
With wordApp.Selection
.InsertAfter "Created time: "
.InsertAfter Now()
End With

'[Select All] and [Copy]
With wordApp.Selection
.WholeStory
.Copy
End With

'pasted to this worksheet "sheet1"
ThisWorkbook.Sheets("sheet1").Range("A1").PasteSpe cial xlPasteValues

'saved word document
wordDoc.SaveAs "test.doc"
wordDoc.Close

'quitted the Word
wordApp.Quit
Set wordDoc = Nothing
Set wordApp = Nothing

End Sub


SAMURA



"fitful_thought" wrote in message
...
Hello,
I'm using excel to create a new document in word.
When the word document is created I would like to select all and copy.
Can I do this from the excel macro?







All times are GMT +1. The time now is 10:39 AM.

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