I am using WORD 97.
I am in the process of producing mail merge letters via microsoft query. On
one of these fields in the original document it has been bookmarked
When the data has been merged I need to run some code which then cross
references this bookmark and inserts various extras dependant on what has
been merged into this particular field.
Please can someone tell me how this can be done so that the following code
is called:
_______________________________________________________________
Sub DocPopulate()
Dim strDivId, Signature As String
'Divisional Identifier taken from Crime Number
strDivId = Left(ActiveDocument.Bookmarks("State").Range.Text, 2)
'File path for signatures so that Ian can update them!
Signature = "U:\WT Business Services\Force Forms\Signatures\" & strDivId &
".gif"
If strDivId = "«R" Then Exit Sub
ActiveDocument.Bookmarks("Ref").Range.Text = strDivId
Select Case strDivId
Case "AA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "BA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "CA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "DA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "EA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "FA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "GA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "HA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "IA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "JA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case "KA"
ActiveDocument.Shapes(1).Select
With Selection
.Text = "put something here"
End With
ActiveDocument.Shapes(2).Select
With Selection
.InlineShapes.AddPicture FileName:= _
Signature, LinkToFile:=False, SaveWithDocument:=True
End With
Case Else
End Select
End Sub
_________________________________________________________________
Thanks in anticipation.
Mark
Peter Jamieson - 29 Mar 2006 19:02 GMT
There are a couple of significant problems here:
a. when you merge, all bookmarks are destroyed in the document created, so
you can't reference the bookmark in the way you expect
b. when you merge to a document, you only get one document, so locating the
objects you want to modify in the output may not be straightforward.
To solve (a), you consider marking the Divisional Identifier in another way,
e.g. using a different text colour.
To solve (b), you could consider using a splitter macro - e.g. see Graham
Mayor and Doug Robbins' work at
http://www.gmayor.com/individual_merge_letters.htm - the add-in will be no
use to you as it needs Word 2002/2003, but the macros later on the page
should be useful.
You would then need
a. to drive the entire merge process using a macro that
- does the merge
- runs a version of one of the splitter macros, adapted so that when you
create each document, you then find the divisional code and apply the
necessary changes (and perhaps change the text colour back to the one you
really want)
Peter Jamieson
>I am using WORD 97.
>
[quoted text clipped - 247 lines]
>
> Mark
Doug Robbins - Word MVP - 29 Mar 2006 19:27 GMT
When you execute the merge, the bookmark will not survive, so you will not
be able to do it that way.
I am not sure just where your data is stored, but if I had to do something
like this, I would use a query in Access that linked two tables, on the
field containing the AA, BA, CA, etc to another table that contained the
path and names of the files containing the data that you want to insert and
the put the mergefield for that field inside an IncludeText field in the
mailmerge main document.
Then you don't need to run any code.

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I am using WORD 97.
>
[quoted text clipped - 247 lines]
>
> Mark