Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Medusa Medusa is offline
external usenet poster
 
Posts: 1
Default Using a macro to insert pictures in a mailmerge template

hello there;

I've creating a mailmerge template in Word 2003. The datasource (in excel)
includes filenames for .jpg images - 1 image per record, set against text
fields (it's actually property details, with a picture of the property).

The text fields are OK, but I recorded a macro, which I attached to the
template document, to type in the 'includePicture' command. The way I want
it to work is that the users open the template, open the datasource, then run
the macro to insert the 'Include picture' command in the final column of a
Word table.

This worked fine the first time I did it, but when I have tested it again,
the process is adding an additional copy of the image against each record in
the merged document - this is incrementing by 1 each time I run the process.

The code in the macro is:
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="IncludePicture""\\\\Printserver\\cblftp\\"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="MERGEFIELD PHOTO"
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=""""
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="\d"
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub

Can anybody help?

Thanks




  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default Using a macro to insert pictures in a mailmerge template

Hi Medusa,

You could use the mailmerge to insert the pictures, without recourse to a macro. The field code to insert & unlink the pictures
would be either:
{IF {INCLUDEPICTURE {IF TRUE "C:\Users\My Document Path\Pictures\«Image»"} \d} {INCLUDEPICTURE {IF TRUE "C:\Users\My Document
Path\Pictures\«Image»"} \d}}
or
{IF {INCLUDEPICTURE {IF TRUE "C:\Users\My Document Path\Pictures\{MERGEFIELD Image}"} \d} {INCLUDEPICTURE {IF TRUE "C:\Users\My
Document Path\Pictures\{MERGEFIELD Image}"} \d}}
where 'C:\Users\My Document Path\Pictures\' is the file path and 'Image' is you data sourcefield name for the images.

Note: The field brace pairs (ie '{ }') for the above examples are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message. Likwise, you can't type or copy & paste the chevrons (ie '« »') - they're part of the actual mergefields,
which you can insert from the mailmerge toolbar.

--
Cheers
macropod
[Microsoft MVP - Word]


"Medusa" wrote in message news
hello there;

I've creating a mailmerge template in Word 2003. The datasource (in excel)
includes filenames for .jpg images - 1 image per record, set against text
fields (it's actually property details, with a picture of the property).

The text fields are OK, but I recorded a macro, which I attached to the
template document, to type in the 'includePicture' command. The way I want
it to work is that the users open the template, open the datasource, then run
the macro to insert the 'Include picture' command in the final column of a
Word table.

This worked fine the first time I did it, but when I have tested it again,
the process is adding an additional copy of the image against each record in
the merged document - this is incrementing by 1 each time I run the process.

The code in the macro is:
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="IncludePicture""\\\\Printserver\\cblftp\\"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="MERGEFIELD PHOTO"
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=""""
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="\d"
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub

Can anybody help?

Thanks





  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Using a macro to insert pictures in a mailmerge template

Try the following

Dim oTable As Table
Dim oCell As Range
Set oTable = ActiveDocument.Tables(1)
ActiveWindow.View.ShowFieldCodes = True
For i = 1 To oTable.Rows.Count
Set oCell = oTable.Cell(i, oTable.Columns.Count).Range
oCell.End = oCell.End - 1
oCell.Fields.Add oCell, wdFieldIncludePicture, _
Text:=Chr(34) & "\\\\Printserver\\cblftp\\ " _
& Chr(34) & " \d", _
Preserveformatting:=False
Set oCell = oTable.Cell(i, oTable.Columns.Count).Range
oCell.End = oCell.End - 6
oCell.Start = oCell.End - 4
oCell.End = oCell.End - 3
oCell.Fields.Add oCell, wdFieldMergeField, _
Text:="PHOTO", Preserveformatting:=False
Next i

See also http://www.gmayor.com/mail_merge_graphics.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Medusa wrote:
hello there;

I've creating a mailmerge template in Word 2003. The datasource (in
excel) includes filenames for .jpg images - 1 image per record, set
against text fields (it's actually property details, with a picture
of the property).

The text fields are OK, but I recorded a macro, which I attached to
the template document, to type in the 'includePicture' command. The
way I want it to work is that the users open the template, open the
datasource, then run the macro to insert the 'Include picture'
command in the final column of a Word table.

This worked fine the first time I did it, but when I have tested it
again, the process is adding an additional copy of the image against
each record in the merged document - this is incrementing by 1 each
time I run the process.

The code in the macro is:
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText
Text:="IncludePicture""\\\\Printserver\\cblftp\\"
Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, _ PreserveFormatting:=False Selection.MoveLeft
Unit:=wdCharacter, Count:=1 Selection.TypeText Text:="MERGEFIELD
PHOTO" Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=""""
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="\d"
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub

Can anybody help?

Thanks



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Macro to Insert Pictures into table - one per row. alex20850 Tables 1 September 26th 08 01:09 AM
Macro Help - sizing pictures Mike Microsoft Word Help 1 February 20th 08 01:28 PM
how to insert watermarked pictures into business card template please help.. frustrated Microsoft Word Help 1 September 11th 05 04:50 PM
Mailmerge with Logo's (pictures) fb0gris1091 Mailmerge 1 April 9th 05 09:41 AM
How to set a macro to insert a second page into a template A. Richardson Microsoft Word Help 5 November 30th 04 11:31 AM


All times are GMT +1. The time now is 10:42 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"