Reading Word document by using Excel Macro

A

Arvind Mane

Can anyone tell me how to read each character from the word document by using
the Excel Macro.
 
J

Joel

Here is three very similar methods

by characters

Sub getcharacters()

Set WdObj = GetObject("c:\temp\test.doc")

RowCount = 1
For Each Char In WdObj.Characters
For CharCount = 1 To Len(Wd)
Range("A" & RowCount) = Mid(Wd, CharCount)
RowCount = RowCount + 1
Next CharCount
Next Char
WdObj.Close
End Sub

By Word

Sub getwords()

Set WdObj = GetObject("c:\temp\test.doc")

RowCount = 1
For Each Wd In WdObj.Words
Range("A" & RowCount) = Wd
RowCount = RowCount + 1
Next Wd
WdObj.Close
End Sub


To use the words to get the characters

Sub getletters()

Set WdObj = GetObject("c:\temp\test.doc")

RowCount = 1
For Each Wd In WdObj.Words
For CharCount = 1 To Len(Wd)
Range("A" & RowCount) = Mid(Wd, CharCount)
RowCount = RowCount + 1
Next CharCount
Next Wd
WdObj.Close
End Sub
 
A

Arvind Mane

Thank you Joel, its working fine.

Joel said:
Here is three very similar methods

by characters

Sub getcharacters()

Set WdObj = GetObject("c:\temp\test.doc")

RowCount = 1
For Each Char In WdObj.Characters
For CharCount = 1 To Len(Wd)
Range("A" & RowCount) = Mid(Wd, CharCount)
RowCount = RowCount + 1
Next CharCount
Next Char
WdObj.Close
End Sub

By Word

Sub getwords()

Set WdObj = GetObject("c:\temp\test.doc")

RowCount = 1
For Each Wd In WdObj.Words
Range("A" & RowCount) = Wd
RowCount = RowCount + 1
Next Wd
WdObj.Close
End Sub


To use the words to get the characters

Sub getletters()

Set WdObj = GetObject("c:\temp\test.doc")

RowCount = 1
For Each Wd In WdObj.Words
For CharCount = 1 To Len(Wd)
Range("A" & RowCount) = Mid(Wd, CharCount)
RowCount = RowCount + 1
Next CharCount
Next Wd
WdObj.Close
End Sub
 

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