Check for changed text

J

John J

Hello all,

I take various parts of a datasource and put them all
together on mail merge to make a unique reference. When
the reference is displayed in the merged document, it has
become text.

It may be that the user needs to update this reference in
some way. Is there any way of checking that the
reference has been updated and storing away the updated
version?

I have thought of scanning capturing the reference when
the document is presented to the user and then on close
of the document scanning it again for the original
version of the reference and if not found using bookmarks
around the reference field to copy away the new edited
version, but this will involve some heavy duty macros
organising and testing. I am hoping there may be some
obvious easier way or Word facility ...

If you can give me any ideas for another approach then
that would be great.

Thank you

John J
 
J

John J.

Hello all again,

With time, you can do anything. If you want the solution
to this, this is what I found:

This macro would run, from an point before the document
is for example printed. Or could be behind a toolbar
button.

Identify where the reference field starts and pass in the
details. I am assuming the refernce field is on its own
line. If not you would need the MoveEndUntil function

....
strOurRef = TrapTheReference("Our ref:")

If strOurRef = "" Then
strOurRef = TrapTheReference("Our reference:")
End If

..

Function TrapTheReference(strSearchText As String) As
String

Dim strSelectedText As String
With Selection
.Find.ClearFormatting
With .Find
.Text = strSearchText
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
End With
.Find.Execute
.MoveRight Unit:=wdCharacter, Count:=2
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
End With
strSelectedText = Selection.Text
Selection.MoveRight Unit:=wdCharacter, Count:=1
TrapTheReference = strSelectedText
End Function

It seems to do the trick. Hope you find it useful and
something to build on. Don't forget any error handling
you may need.

Cheers

John J.
 

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