select all & copy in word from macro in excel

  • Thread starter Thread starter fitful_thought
  • Start date Start date
F

fitful_thought

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,
 
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
 
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").PasteSpecial xlPasteValues

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

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

End Sub


SAMURA
(e-mail address removed)
 
Arigato Samura,
--
Regards,
Lindstrom

SAMURA said:
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").PasteSpecial xlPasteValues

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

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

End Sub


SAMURA
(e-mail address removed)


fitful_thought said:
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?
 
Back
Top