P
Paulkelly77
Hello there,
I am trying to write a VBS script to run over a collection of 4000 or
so documents that were created using a word template which uses a form
on document creation that people fill in. This form then inserts text
at various bookmarks throughout the document. I need to now extract
the text at some of the bookmark points using the MID function, before
I can do that I need to get accurate information about the various
bookmark starting points.
Using the following code I locate the position of one of the bookmarks
(bookMeetingDate) in a test document, it reports position 990, I know
the text that is inserted just after the bookmark in my test document
is 18 January, when I do an InStr(oRangeWhole) for that text I get
position 559 reported back to me, can anyone shed some light on why
there is a difference in these two values and whhat I might do to get
an accurate value of the bookmark position?
18 January only appears once in the test document.
Option Explicit
Dim oWord
Set oWord = CreateObject ("Word.Application")
Dim oDoc
Set oDoc = oWord.Documents.Open("C:\docparser\I-06-01.doc",True,True)
Dim oRangeWhole
Set oRangeWhole = oDoc.Range
WScript.echo oDoc.Bookmarks("bookMeetingDate").Start ' Reports 990
WScript.echo InStr(oRangeWhole,"18 January") ' Reports 559
oDoc.Close(False)
oWord.Quit
Set oDoc = Nothing
Set oWord = Nothing
I am trying to write a VBS script to run over a collection of 4000 or
so documents that were created using a word template which uses a form
on document creation that people fill in. This form then inserts text
at various bookmarks throughout the document. I need to now extract
the text at some of the bookmark points using the MID function, before
I can do that I need to get accurate information about the various
bookmark starting points.
Using the following code I locate the position of one of the bookmarks
(bookMeetingDate) in a test document, it reports position 990, I know
the text that is inserted just after the bookmark in my test document
is 18 January, when I do an InStr(oRangeWhole) for that text I get
position 559 reported back to me, can anyone shed some light on why
there is a difference in these two values and whhat I might do to get
an accurate value of the bookmark position?
18 January only appears once in the test document.
Option Explicit
Dim oWord
Set oWord = CreateObject ("Word.Application")
Dim oDoc
Set oDoc = oWord.Documents.Open("C:\docparser\I-06-01.doc",True,True)
Dim oRangeWhole
Set oRangeWhole = oDoc.Range
WScript.echo oDoc.Bookmarks("bookMeetingDate").Start ' Reports 990
WScript.echo InStr(oRangeWhole,"18 January") ' Reports 559
oDoc.Close(False)
oWord.Quit
Set oDoc = Nothing
Set oWord = Nothing