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 / November 2004

Tip: Looking for answers? Try searching our database.

font question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
phil - 17 Nov 2004 21:58 GMT
how do I control the data from a userform when it going to a book mark in a
document
I wish to format the text into italics and bold which can be turned on or
off  with controls in the userform
also is it possible to make the text into capitals or lower case through the
userform before its transferred into the document
thanks phil
Jean-Guy Marcil - 17 Nov 2004 22:21 GMT
phil was telling us:
phil nous racontait que :

> how do I control the data from a userform when it going to a book
> mark in a document
[quoted text clipped - 3 lines]
> through the userform before its transferred into the document
> thanks phil

Assuming you have userform checkbox called chkBold
Assuming you have a userform textbox called txbInfo
Assuming you have a bookmark called "here"

Assuming that
   chkBold = True
   txbInfo = "Text to insert in the bookmark range."

then this should work:

'_______________________________________
Dim BookName As String
Dim BookRange As Range

BookName = "here"

With ActiveDocument
   Set BookRange = .Bookmarks(BookName).Range
   With BookRange
       .Text = txbInfo
       .Font.Bold = chkBold
   End With
'Redefine bookmark because it was lost when the text was inserted.
   .Bookmarks.Add BookName, BookRange
End With
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

phil - 18 Nov 2004 10:56 GMT
is there a way to apply this to many bookmarks without writing code for each
bookmark
thanks phil

> phil was telling us:
> phil nous racontait que :
[quoted text clipped - 33 lines]
> End With
> '_______________________________________
Jean-Guy Marcil - 18 Nov 2004 15:08 GMT
phil was telling us:
phil nous racontait que :

> is there a way to apply this to many bookmarks without writing code
> for each bookmark
> thanks phil

Build an array with the bookmark names, textboxes values and another with
the checkboxes values and slap the code in a Loop.
Something like (Of course, you will have to build you arrays from your
userform values instead of using Strings and Split):

'_______________________________________
Dim BookRange As Range

Dim BookNames As String
Dim chkboxValues As String
Dim TextBoxes As String
Dim BookArray() As String
Dim chkBoxArray() As String
Dim TextArray() As String

Dim i As Long

BookNames = "here/there/over_here/that_spot/finally"
chkboxValues = "True/False/True/True/False"
TextBoxes = "First Text/Second Text/Third Text/Fourth Text/Fifth Text"
BookArray() = Split(BookNames, "/")
chkBoxArray() = Split(chkboxValues, "/")
TextArray() = Split(TextBoxes, "/")

With ActiveDocument
   For i = 0 To 4
       Set BookRange = .Bookmarks(BookArray(i)).Range
       With BookRange
           .Text = TextArray(i)
'CBool may not be necessary depending on how you build this particular array
           .Font.Bold = CBool(chkBoxArray(i))
       End With
   'Redefine bookmark because it was lost when the text was inserted.
       .Bookmarks.Add BookArray(i), BookRange
   Next
End With
'_______________________________________

See
http://www.officecomputertraining.com/vbtutorial/tutpages/page22.asp
or
http://www.vbtutor.net/lesson13.html

for help on Arrays (The sites are for VB, but Arrays are essentially the
same in VBA).
Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Rate this thread:






 
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.