Problem creating ADDIN Fields in Word

G

Gunther Maier

Hi,

I am trying to imitate the way Endnotes stores citations in word
documents. This is done via an ADDIN field. This field shows, for
example, author and year in the regular display of Word, and a long XML
string when the filed codes are displayed. According to ma checking, the
author and year information is stored in .Result.Text in the field, the
XML string in .Code.Text.

I can read Code.Text and Result.Text from an existing ADDIN field as
with the following macro:

Sub Makro3()

Dim f As Word.Field

Set f = ActiveDocument.Range.Fields.Item(1)
MsgBox (f.Result.Text)
MsgBox (f.Code.Text)
f.Result.Text = "BLA, BLA, BLA"

End Sub

This macro ALSO replaces the original .Result.Text by my new text "BLA,
BLA, BLA". This is also reflected in Word in the expected way.

NOW COMES THE PROBLEM:

While everything works fine with existing ADDIN fliends, when I create
my own ADDIN field, I CANNOT store anything in .Result.Text, as in the
following macro (the length of the Text should not bother you, I tried
different things there):

Sub Makro2()

Dim f As Word.Field

Set f = Selection.Fields.Add(Range:=Selection.Range,
Type:=wdFieldAddin, Text:= _
"EN.CITE
<EndNote><Cite><Author>Lefebvre</Author><Year>1991</Year><RecNum>961</RecNum><record><rec-number>961</rec-number><ref-type
name=""Book"">6</ref-type><contributors><authors><author>Lefebvre,
H.</author></authors></contributors></Cite></EndNote>",
PreserveFormatting:=False)
f.Result.Text = "BLA, BLA, BLA"

End Sub

Word does not complain or produce any error message when I run this
macro. However, the line 'f.Result.Text = "BLA, BLA, BLA"' does not
alter the .Result.Text of the field as in the previous macro. It is
still equal to Nothing as before. The text is actually written after the
ADDIN field into the document.

Does anyone have an idea what causes this problem?

Kind regards
Gunther Maier
 
P

Peter Jamieson

Create the field as another type (e.g. wdFieldQuote), set the Result, then
change the field type e.g. (by replacing QUOTE with ADDIN)

Peter Jamieson
 
G

gunther maier

MANY thanks! That does the trick - although I don't understand why it
does not work the other way and why it has to be this way.

Thanks again
Gunther Maier
 
P

Peter Jamieson

I don't know either but I guess it has always been that way and probably
won't change now.

Peter Jamieson
 

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