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
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