I need to write a script to fetch text from an opened word document. I am
using the below script;
---------------------------------------------------------------------------------------------
Dim wrdApp
Dim wrdDoc
Dim tString, tRange
Dim p, startRange, endRange
Dim searchString
Set wrdApp = GetObject(,"Word.Application")
Set wrdDoc=wrdApp.ActiveDocument
MsgBox wrdApp.ActiveDocument.Name
tString = ""
With wrdDoc
For p = 1 To .Paragraphs.Count
startRange = .Paragraphs(p).Range.Start
endRange = .Paragraphs(p).Range.End
Set tRange = .Range(startRange, endRange)
tString = tString & tRange.Text
tString = Left(tString, Len(tString) - 1) 'exclude the paragraph-mark
Next
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
MsgBox tString 'captured text
---------------------------------------------------------------------------------------------
Unfortunately, I am encountering an error with few documents. The error
message is - 'This method or property is not available because the 'object
refers to a protected area of the document'. This is happening for the line -
'tString = tString & tRange.Text'
Your help is highly appreciated.
Joshy
847.667.7420
Dawn Crosier - 28 Nov 2005 20:48 GMT
What specific runtime error are you receiving? Have you
physically reviewed the problem documents to determine whether
they are password protected or otherwise have some protection
settings?

Signature
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"
This message is posted to a newsgroup. Please post replies and
questions to the newsgroup so that others can learn as well.
I need to write a script to fetch text from an opened word
document. I am
using the below script;
---------------------------------------------------------------------------------------------
Dim wrdApp
Dim wrdDoc
Dim tString, tRange
Dim p, startRange, endRange
Dim searchString
Set wrdApp = GetObject(,"Word.Application")
Set wrdDoc=wrdApp.ActiveDocument
MsgBox wrdApp.ActiveDocument.Name
tString = ""
With wrdDoc
For p = 1 To .Paragraphs.Count
startRange = .Paragraphs(p).Range.Start
endRange = .Paragraphs(p).Range.End
Set tRange = .Range(startRange, endRange)
tString = tString & tRange.Text
tString = Left(tString, Len(tString) - 1) 'exclude the
paragraph-mark
Next
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
MsgBox tString 'captured text
---------------------------------------------------------------------------------------------
Unfortunately, I am encountering an error with few documents. The
error
message is - 'This method or property is not available because
the 'object
refers to a protected area of the document'. This is happening
for the line -
'tString = tString & tRange.Text'
Your help is highly appreciated.
Joshy
847.667.7420