simple question

M

marwan hefnawy

Dear felleows,
I'm new to word programming, so my question may be simple.
I have a report that contains the sentence "The result is" then I have to
write a calculated number after this sentence.
How can I do it with VBA?
I know how to calculate my number but I don't know how to put it in the
right place in the document.
Thanks
 
D

Doug Robbins - Word MVP

Hi Marwan,

There are a couple of ways.

1. Insert a Bookmark at the location that you want the result to appear
and use:

ActiveDocument.Bookmarks("BookmarkName").Result.InsertBefore [result of
your calculation]

2. Insert a { DOCVARIABLE "varname" } field where you want the
calculation to appear and use

ActiveDocument.Variables( "varname").Value = [result of your
calculation]
ActiveDocument.Fields.Update

The second one is probably more secure, because a bookmark or its contents
can inadvertently be deleted. If the { DOCVARIABLE } field were deleted, it
could always be reinserted and will display its value as the only way that
can be changed is by use of VBA.

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
 

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