Get data from Word to Excel using a macro in Excel

T

Trefor

To explain what I am trying to do in some detail: (using Office 2003)

I would like to run a macro in Excel that:

1. Checks to see if there is an open Word document. (I don't want to have to
specify a name or have to open the file from within Excel)

2. Select and copy the data from word to excel. (The word document (for some
reason beyond my control) has text boxes set in autoshapes to look like
tables, each cell within the “table†has a text box and the text box has
several lines of text in it (names and addresses for example))

3. I am guessing for simplicity it would be easier to just grab everything,
then paste it into a "scratch" area in excel, and then I can pick and choose
what I want from the scratch area.

I am fairly happy with macro's/VBA in excel, what I am not familiar with is
VBA in Word or switching between the two.

From the Excel News Group I put to together the following code in Excel, but
it errors:

("Microsoft Word x.xx Object library". <--- is set in Excel)


Sub testme01()

Dim WDApp As Object
Dim WDDoc As Object
Dim mywdRange As Word.Range

Set WDApp = Nothing
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
MsgBox "Word isn't running!"
Exit Sub
End If

WDApp.Visible = True

Set WDDoc = Nothing
On Error Resume Next
Set WDDoc = WDApp.ActiveDocument
On Error GoTo 0

If WDDoc Is Nothing Then
MsgBox "No activedocument in Word"
Exit Sub
End If

With mywdRange

Selection.WholeStory <------ This Line Errors with 438

Selection.Tables(1).Select <------ This Line Errors with 438

Selection.SelectRow
Selection.Copy
End With

WDDoc.Selection.WholeStory <------ This Line Errors with 438
End Sub


I just tried creating a new word doc, with just one word on a blank page,
same problem.

Any suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top