! Bookmark Referencing from Code !

W

Wembly

Hi,

I have set up bookmarks and other merged fields in a word
DOT file and want to use code to perform some calculations
to populate certain bookmarked fields.

I was wondering if it was possible to reference a bookmark
from a Word doc, and if so, how it is written?

E.g. The GrossAmount is the bookmark in Word. And the
Datafields "Dollar1/2/3" are referencing "Documents
("filename.DOT").mailmerge.datasource"

GrossAmount = .DataFields("Dollar1").Value _
+ .DataFields("Dollar2").Value _
+ .DataFields("Dollar3").Value

If there is a way to reference bookmarks, which event do I
put this in so that Word knows when to sum it after the
fields have been merged (because prior to merge, there is
no data there for it to sum).

Thanks

Wembly.
 
P

Peter Jamieson

I think you may be making this more complicated than it needs to be.

Typically, if you have merge data fields "Dollar1", "Dollar2", "Dollar3",
you should be able to sum them in a nested field that looks (at worst) like

{ ={ MERGEFIELD Dollar1 }+{ MERGEFIELD Dollar2 }+{ MERGEFIELD Dollar3 } }

and avoid any VBA at all. Or, in some cases, you may be able to perform the
calculation in a query in the data source (it depends on the data source).

/If/ you are trying to produce a "grand total" of Dollar1+Dollar2+Dollar3
for all the records in your merge, you should stil be able to do it by
adding the new amounts into a bokmark using e.g.

{ IF { MERGEREC } = 1
"{ SET mytotal 0 }"
"{ SET mytotal { ={ REF mytotal}
+{ MERGEFIELD Dollar1 }
+{ MERGEFIELD Dollar2 }
+{ MERGEFIELD Dollar3 } }" }

But maybe what you are doing requires another approach, in which case please
tell us which
a. version of Word you are using
b. why the above approach will not work

If you are usig Word 2002 or later, there are mailmerge events including an
event that fires for each record in the data source and allows you to modify
the mail merge main document just before the record is merged.
 

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