How to insert mergefield inside a includepicture field using VB

F

Feng

Hi,

currently, I use the following code:
Dim fldCode as String
WordMergeField = WordMergeFields.Add(WordSelection.Range, type)
fldCode = WordMergeField.Code.Text
WordMergeField.Delete()
WordInline.AddPicture("C:\proj\hrosen\JPT0803\Signature\" & fldCode & ".bmp", True, False, WordSelection.Range)

The problem is Code.text removes the brackets around the wordMergeField. the merge field I'm using actually provides the name of each image. Basically I want the Document to show up something like,
{INCLUDEPICTURE "C:\\proj\\hrosen\\JPT0803\\Signature\\{MergeField LIST}.bmp" \d }
instead, I'm getting
{INCLUDEPICTURE "C:\\proj\\hrosen\\JPT0803\\Signature\\MergeField LIST.bmp" \d }
with this code. What can I do to change this?

Thanks
 
D

Doug Robbins - Word MVP

Hi Feng,

Unless they are dimmed somewhere else, your code uses a whole lot of terms
that mean nothing to me (or VBA)

WordMergeField
WordMergeFields
WordSelection
WordInline

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Feng said:
Hi,

currently, I use the following code:
Dim fldCode as String
WordMergeField = WordMergeFields.Add(WordSelection.Range, type)
fldCode = WordMergeField.Code.Text
WordMergeField.Delete()
WordInline.AddPicture("C:\proj\hrosen\JPT0803\Signature\" & fldCode &
".bmp", True, False, WordSelection.Range)
The problem is Code.text removes the brackets around the wordMergeField.
the merge field I'm using actually provides the name of each image.
Basically I want the Document to show up something like,
 
F

Feng

I'm extremely sorry, I hope this is better

Dim WordDoc As Word.Document
Dim WordObject As Word.Application
Dim WordMerge As Word.MailMerge
Dim WordMergeFields As Word.MailMergeFields
Dim WordSelection As Word.Selection
Dim WordMergeField As Word.MailMergeField
Dim WordFields As Word.Fields
Dim WordInline As Word.InlineShapes
Dim fldCode as String

WordObject = CreateObject("Word.Application")
WordObject.Visible = True

WordDoc = WordObject.Documents.Open("C:\proj\hrosen\JPT0803\f011.doc")
WordDoc.Select()
WordSelection = WordObject.Selection()
WordInline = WordDoc.InlineShapes()
WordMerge = WordDoc.MailMerge()
WordFields = WordDoc.Fields()

WordMergeFields = WordMerge.Fields()
WordMergeField = WordMergeFields.Add(WordSelection.Range, type)
fldCode = WordMergeField.Code.Text
WordMergeField.Delete()
WordInline.AddPicture("C:\proj\hrosen\JPT0803\Signature\" & fldCode &
".bmp", True, False, WordSelection.Range)

The problem is Code.text removes the brackets around the wordMergeField.
the merge field I'm using actually provides the name of each image.
Basically I want the Document to show up something like,
{INCLUDEPICTURE "C:\\proj\\hrosen\\JPT0803\\Signature\\{MergeField
LIST}.bmp" \d }
instead, I'm getting
{INCLUDEPICTURE "C:\\proj\\hrosen\\JPT0803\\Signature\\MergeField
LIST.bmp" \d }
 

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