HELP PLEASE! Inserting a chosen paragraph then inserting form fields into that chosen paragraph!

A

Adi

Hello!

For an assignment I have been asked to standardise a word document
using VBA for a life assurance company. It is basically a letter that
is sent out to clients to confirm what type of policy they have taken
out and includes various details.

However I have come stuck with one part of it. Basically depending on
what type of policy is taken out (there are 3 possible choices)
depends on which of 3 different paragraphs have to be included in the
letter.

Firstly then: is there a way that this can be done with VBA or
Macro's?

Also, within the paragraphs there are "variables" that need to be
entered using a userform. Normally I would enter a bookmark in the
place that the variable data would be inserted, but because the
paragraph isn't there until the policy is selected by the user I can't
find a way of inserting a bookmark! Is there some way a bookmark could
be included in the code? Or is there another way that's completely
different?

Many thanks in advance for anyone who can help - my lecturer for this
module stunned me today when she told me she had "limited" knowledge
about visual basic, yet this assignment is all about VBA!!!!
 
J

Jezebel

Adi said:
Hello!

For an assignment I have been asked to standardise a word document
using VBA for a life assurance company. It is basically a letter that
is sent out to clients to confirm what type of policy they have taken
out and includes various details.

However I have come stuck with one part of it. Basically depending on
what type of policy is taken out (there are 3 possible choices)
depends on which of 3 different paragraphs have to be included in the
letter.

Firstly then: is there a way that this can be done with VBA or
Macro's?

VBA and macros are the same thing. You could either put all three paragraphs
in the letter template, each defined by a bookmark. Then according to policy
type delete the two you don't want. Or, define the three paragraphs as
Autotext entries and insert the one you want.

Also, within the paragraphs there are "variables" that need to be
entered using a userform. Normally I would enter a bookmark in the
place that the variable data would be inserted, but because the
paragraph isn't there until the policy is selected by the user I can't
find a way of inserting a bookmark! Is there some way a bookmark could
be included in the code? Or is there another way that's completely
different?

If you use method 1 you still can use bookmarks; but a better approach is to
use custom document properties. In code, set the value by setting the
property value. In the document, use a DocProperty field where you want the
value to appear. This will work with either of the paragraph methods, since
Autotext entries may include fields.
 
A

Adi

Many thanks for the speedy reply to my problem - I can now see light
at the end of the tunnel!

I'm sorry to call on your expertise again, but I am a "newbie" to VBA
and I know more than my lecturer so no help there!

I will go with your first method as it seems the simplist but can you
tell me what the code is for deleting the paragraphs please? I have
tried searching newsgroups and web pages and reading up in books for
the answer but I can't seem to find it!

Again, my humble thanks for yours and anybody else's help!!
 
J

Jezebel

If you have a bookmark called "Par1", then this deletes whatever the
bookmark refers to --

ActiveDocument.Bookmarks("Par1").Range.Delete
 

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