Bookmarks within VB?

N

Newforms

Hello all,

I have put together this form to fill out bookmarks within a word
document/template; but have become stumped (please bear in mind I have
been working in VB for just a few days now.. I'm a graphic designer at
heart :). My current problem is that where I insert the text at the
"pleasenote" bookmark I need to fill out the variables within the text
labelled "termly" and "amount", also in the third piece of text you
will see I have three amounts to fill out.

Now with the text being generated I dont know a way of including the
bookmarks in the inserted text, or whether they will update when the
button is pressed... I could go on but am confusing myself.

So basically: I want to be able to change variables in the text
inserted at bookmarks.

Without further delay:


Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("accountnumber").Range _
.InsertBefore TextBox1
.Bookmarks("drawdownamount").Range _
.InsertBefore TextBox2
.Bookmarks("undrawnbalance").Range _
.InsertBefore TextBox3
.Bookmarks("interestrate").Range _
.InsertBefore TextBox4
End With
Dim mytext As String
If OptionButton1.Value = True Then
pleasenote = "per annum and your regular <termly> payments will be
$<amount> commencing <date>."
ElseIf OptionButton2.Value = True Then
pleasenote = "per annum and your regular <termly> payments will be
$<amount> commencing <date>."
ElseIf OptionButton3.Value = True Then
pleasenote = "per annum and your regular <termly> payments will
vary as follows, depending on the number of days in the month; 31 day
months $<amount>, 30 day months $<amount>, February month $<amount>."
Else
mytext = "You need to select either weekly, fortnightly, or
monthly"
End If
ActiveDocument.Bookmarks("pleasenote").Range.InsertBefore pleasenote
ActiveDocument.Bookmarks("pleasenote").Range.Font.Size = 6
ficdd.Hide
End Sub


Any help appreciated, thanks in advance! Jon
 
J

Jezebel

I think there's maybe a little misunderstanding here. From your description
you want to set the value of the bookmark text within the document; but your
code seems to be trying to insert text in front of the bookmarks.

To replace the content of a bookmark, use

ActiveDocument.Bookmarks("accountnumber").Range = TextBox1
etc

Note that this deletes the bookmark. You need to redefine it if you need to
be able to run the code more than once.


Having said all that, a better way to do this sort of thing is to use
Document Properties and DocProperty fields. The advantages are a) you can
insert the same piece of data in any number of places in the document in one
step (instead of having to set multiple bookmarks); b) you don't have to
muck around directly with the content of the document; and c) the property
doesn't get deleted when you set the value.
 
N

Newforms

Hi Jezebel and thank you for your help. I think my waffle may have been
a little misleading, my apologies it was written in the last 5 minutes
of my day at work and I had code coming out of my ears!

I need to insert text at a bookmark (which the code does at the
moment)...
Then need to have control over the text that has been inserted, i.e. be
able to:


ElseIf OptionButton2.Value = True Then

Insert this text, then input the <termly>, <amount>, and <date>,
possibly on a follow up form?
 
R

Russ

Newforms,
Hi Jezebel and thank you for your help. I think my waffle may have been
a little misleading, my apologies it was written in the last 5 minutes
of my day at work and I had code coming out of my ears!

I need to insert text at a bookmark (which the code does at the
moment)...
Then need to have control over the text that has been inserted, i.e. be
able to:
Your description is still a little confusing. You already had control over
the text before you inserted it. Otherwise you wouldn't have been able to
insert it. Can't you test it just before you insert it?
 

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