Merge using Bookmarks and VB6

V

Vik Holmberg

I use bookmarks, not formfields, to merge data from a vb6
app into a word template through automation. This
process works very well and is much faster than using
bookmark formfields. My problem is some bookmarks do not
retain/hold formatting codes such as bold & underline.
This seems to happen when there are multiple columns in a
table and the bookmark is the first character in the
column. Is there someway to get all the bookmaks to take
the same formatting?

When I used formfield bookmarks, I could leave underlines
in places where no data was written. Using just a
bookmark, the space is empty and looks bad. If I insert
a "_" after the bookmark, I end up with a "X_", without
the quotes, in the space. This smippet is an example of
how I merge to the template:

oWD.Bookmarks("A1C20").Range.Text = "X"

Can I extend the range to replace the first character
after the insertion point with the X? As always, I thank
the contributors for their time and effort, Vik.

Please don't reply to the email address since it is my
MSDN alias.
 
D

Doug Robbins - Word MVP

Hi Vik,

If you use { DOCVARIABLE "varname" } fields instead of bookmarks, you can
add the \* CHARFORMAT switch to the field and the the formatting that you
apply to the D of DOCVARIABLE will be applied to the result. Get you Access
code to create variables by using

[Document Object].Variables("varname").Value = [data from Access]

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
 
V

Vik Holmberg

Thank you, Doug, for your reply.
I was able to get rid of the underline after the bookmark using the
following code:

oWD.Bookmarks("A2O1").Range.MoveEnd Unit:=1, Count:=1
oWD.Bookmarks("A2O1").Range.Delete
oWD.Bookmarks("A2O1").Range.Text = "X"

I was able to format all the bookmarks except those that were the first
entry in a table cell, followed by text. Those, I deleted, added a space,
and reinserted the bookmark after the space, using the same name. With the
space before the bookmark, I could select it and apply formatting. The
reason I went to all this trouble is that the document prints more than a
hundred times faster with bookmarks than with field codes. Thanks again,
this is not the first reply you have given me, Vik.

Doug Robbins - Word MVP said:
Hi Vik,

If you use { DOCVARIABLE "varname" } fields instead of bookmarks, you can
add the \* CHARFORMAT switch to the field and the the formatting that you
apply to the D of DOCVARIABLE will be applied to the result. Get you Access
code to create variables by using

[Document Object].Variables("varname").Value = [data from Access]

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
Vik Holmberg said:
I use bookmarks, not formfields, to merge data from a vb6
app into a word template through automation. This
process works very well and is much faster than using
bookmark formfields. My problem is some bookmarks do not
retain/hold formatting codes such as bold & underline.
This seems to happen when there are multiple columns in a
table and the bookmark is the first character in the
column. Is there someway to get all the bookmaks to take
the same formatting?

When I used formfield bookmarks, I could leave underlines
in places where no data was written. Using just a
bookmark, the space is empty and looks bad. If I insert
a "_" after the bookmark, I end up with a "X_", without
the quotes, in the space. This smippet is an example of
how I merge to the template:

oWD.Bookmarks("A1C20").Range.Text = "X"

Can I extend the range to replace the first character
after the insertion point with the X? As always, I thank
the contributors for their time and effort, Vik.

Please don't reply to the email address since it is my
MSDN alias.
 

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