PDA

View Full Version : Solved: Copy from Word document and paste into new Excel document



crmpicco
05-17-2005, 06:50 AM
I have a MS Word document.

I am looking for a way to copy all of the contents of the file into a new Excel worksheet/workbook.

The problem (i think) is that my Visual Basic project is a XLA file. Can i still do this with the same project?

So, basically:

Copy all the contents of a MS Word document
Open a new MS Excel Document
Paste the content into the Excel Document.

TIA.

Picco

MOS MASTER
05-17-2005, 10:42 AM
Hi Picco, :D

I assume the automation is done from Excel?

If so I see no reason why you couldn't have a sub in your addin that would perform the action..

The sub could look something like:
Option Explicit
Sub WordToNewExcel()
'Set reference to Microsoft Word (version) object library
Dim oApp As New Word.Application
Dim oDoc As Word.Document
Dim sPath As String
sPath = ThisWorkbook.Path & Application.PathSeparator & "test.doc"
Set oDoc = oApp.Documents.Open(Filename:=sPath)

oDoc.Range.Copy
oDoc.Close False

With Application
.Workbooks.Add
.ActiveSheet.Paste
End With

oApp.Quit False
Set oDoc = Nothing
Set oApp = Nothing
End Sub


Enjoy! :whistle:

crmpicco
05-18-2005, 02:22 AM
that worked gr8 - thanx

MOS MASTER
05-18-2005, 09:51 AM
You're Welcome! :beerchug: