Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fetching text from MSWord protected area - 22 Nov 2005 20:05 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.