Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Bookmarks within VB?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Newforms - 18 Sep 2006 05:57 GMT
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
Jezebel - 18 Sep 2006 07:26 GMT
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.

> Hello all,
>
[quoted text clipped - 47 lines]
>
> Any help appreciated, thanks in advance! Jon
Newforms - 18 Sep 2006 22:39 GMT
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
> >    pleasenote = "per annum and your regular <termly> payments will be
> > $<amount> commencing <date>."

Insert this text, then input the <termly>, <amount>, and <date>,
possibly on a follow up form?
Russ - 09 Oct 2006 03:08 GMT
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
[quoted text clipped - 4 lines]
> 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?

> ElseIf OptionButton2.Value = True Then
>>>    pleasenote = "per annum and your regular <termly> payments will be
>>> $<amount> commencing <date>."
>
> Insert this text, then input the <termly>, <amount>, and <date>,
> possibly on a follow up form?

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.