Help Read data from Word into Excel

rob737

Board Regular
Joined
May 12, 2015
Messages
129
Hi Forum

Hope all is well. I am trying to learn how to read text from a word document into excel.

I copied the below snipped from the internet and passed to a module. I understand most of it but I am a bit of a novice so I was hoping for some help to get started.


I have created a sample document in the desired path and a bookmark call “GetData”

As soon as I run the macro I get:

Compile Error
User-Defined type not defined

I would suggest these are the lines

Dim appWord As Word.Application
Dim wrdDoc As Word.Document

Full Code
Sub GrabIt()
Dim appWord As Word.Application
Dim wrdDoc As Word.Document
Dim file
Dim myPath As String

Dim myArray()
Dim j As Long
Dim TempString As String
Dim var

myPath = "c:\zzz\Test\TestWord\"
file = Dir(myPath & "*.doc")

Set appWord = CreateObject("Word.Application")
Do While file <> ""
Set wrdDoc = appWord.Documents.Open _
(Filename:=myPath & file)
TempString = wrdDoc.Bookmarks("GetData").Range.Text
TempString = Left(TempString, Len(TempString) - 1)

ReDim Preserve myArray(j)
myArray(j) = TempString
j = j + 1
wrdDoc.Close wdDoNotSaveChanges
Set wrdDoc = Nothing
file = Dir()
Loop

appWord.Quit
Set appWord = Nothing
' now have an array of all the bookmarked data
' from all the documents, so dump into Excel file
Worksheets("Sheet1").Activate
Range("A2").Select
ActiveCell.Value = myArray(var)
ActiveCell.Offset(1, 0).Activate
For var = 1 To j - 1
ActiveCell.Value = myArray(var)
ActiveCell.Offset(1, 0).Activate
Next
End Sub

I have done a fair bit of work with excel and mail and I needed to add some modules into excel to get the mail interface to work do I need to do the same with word.

Would appreciate some help with getting started here

Many thanks
Best Regards

Rob
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,215,095
Messages
6,123,072
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top