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 / March 2006

Tip: Looking for answers? Try searching our database.

Run code after mail merge

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 29 Mar 2006 16:02 GMT
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
 
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.