Capture text from Word 2k-Err mesg 'object refers to a protected a

  • Thread starter Fetching text from MSWord protected area
  • Start date
F

Fetching text from MSWord protected area

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
 
D

Dawn Crosier

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?

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

"Fetching text from MSWord protected area" <Fetching text from
MSWord protected (e-mail address removed)> wrote in message
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
 

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

Similar Threads


Top