Re: Strange MERGEFIELD insertion behaviour.....

From: Robin Tucker (idontwanttobespammedanymore_at_reallyidont.com)
Date: 05/13/04


Date: Thu, 13 May 2004 10:15:52 +0100

Err, I included a code sample. Here it is again:

Dim theInfo as String

theInfo = "Camera Spot 1"
Dim theText As String = "MERGEFIELD " + "ASSET_Named_Tool" + "=" + theInfo

m_Application.Selection.Fields.Add(Range:=m_Application.Selection.Range, _

Type:=Word.WdFieldType.wdFieldEmpty, _
                                                        Text:=CType(theText,
Object), _

PreserveFormatting:=True)

"Word Heretic" <myfullname@tpg.com.au> wrote in message
news:48i5a05oe3f224327ug6m8semods0amjrq@4ax.com...
> G'day "Robin Tucker" <idontwanttobespammedanymore@reallyidont.com>,
>
> Code sample please
>
>
> Steve Hudson - Word Heretic
> Want a hyperlinked index? S/W R&D? See WordHeretic.com
>
> steve from wordheretic.com (Email replies require payment)
>
>
> Robin Tucker reckoned:
>
> >I'm trying to programmatically insert MERGEFIELD items into my document.
> >They all seem to work ok, except those I need to add parameters to. For
> >example, the following mergefield needs to be inserted:
> >
> >"MERGEFIELD ASSET_Named_Tool=Camera Spot 1"
> >
> >ie. I want a merge field included called "ASSET_Named_Tool=Camera Spot
1".
> >When I come to generate a report using this template, I can parse the
> >mergefield and extract the value I need called "Camera Spot 1". Anyway,
I
> >digress. When I manually insert a mergefield using the add Field dialog,
> >giving the field the name ASSET_Named_Tool=Camera Spot 1, the result is
as
> >expected (ie. I get the << >> brackets around the entire string).
> >
> >When I do the same thing programmatically, it "cuts off" the string at
the
> >end of "Camera". I guess because it isn't too keen on spaces in field
names.
> >However, if I right click on the newly inserted field and "Edit Field",
then
> >click ok when the edit field dialog is shown, the string seems to be
changed
> >to be correct!
> >
> >Summary:
> >
> >(1) Manual insertion produces correct result:
> >«ASSET_Named_Tool=Camera Spot 1»
> >(2) Programmatic insertion produces erroneous result:
> >«ASSET_Named_Tool=Camera»
> >(3) Programmatic insertion, followed by manual "Edit Field", produces
> >correct result.
> >
> >Here is the code I'm using to add the field:
> >
> >Dim theInfo as String
> >
> >theInfo = "Camera Spot 1"
> >Dim theText As String = "MERGEFIELD " + "ASSET_Named_Tool" + "=" +
theInfo
> >
> >m_Application.Selection.Fields.Add(Range:=m_Application.Selection.Range,
_
> >
> >Type:=Word.WdFieldType.wdFieldEmpty, _
> >
Text:=CType(theText,
> >Object), _
> >
> >PreserveFormatting:=True)
> >
> >Thanks for any help you can give me.
> >
> >
> >Robin
> >
>



Relevant Pages

  • Re: Strange MERGEFIELD insertion behaviour.....
    ... I included a code sample. ... Dim theInfo as String ... > Steve Hudson - Word Heretic ... >>Dim theInfo as String ...
    (microsoft.public.word.vba.beginners)
  • Re: Converting RTF to DOCs
    ... Steve Hudson - Word Heretic ... > Dim strFile As String ...
    (microsoft.public.word.vba.general)
  • Re: XML in a Textbox
    ... thanks for the approach and code sample re the 1st and third char not be ... correct I either don't understand this or its not a problem on the XML I'm ... > The following routine creates a string from an XML document with all ... > and then read the contents of the memStream into a string. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Strange MERGEFIELD insertion behaviour.....
    ... Oh actually.....my code did include MERGEFIELD, but my example did not (I'm ... You are inserting an empty field. ... > Steve Hudson - Word Heretic ... >>Dim theInfo as String ...
    (microsoft.public.word.vba.general)
  • Re: Strange MERGEFIELD insertion behaviour.....
    ... Oh actually.....my code did include MERGEFIELD, but my example did not (I'm ... You are inserting an empty field. ... > Steve Hudson - Word Heretic ... >>Dim theInfo as String ...
    (microsoft.public.word.vba.beginners)