#1
|
|||
|
|||
How to I make text Bold in a User Form -Visual Basic
Hello,
I have created a Macro enabled template with User form that automatically opens when the document is opened. One of the issues I am having is trying to figure out how to have the text in a field come out to the document in Bold format. Does anyone know how to do this? I have attached a screenshot Thanks |
#2
|
||||
|
||||
Hi gurp,
If you want the text on the userform to appear bold, set the font attribute for that element to bold. For example: TextBox1.Font.Bold = True If you want the output in the document to be bolded, set a range object to the destination, populate the range, then format the range as bold. For example: Code:
Dim Rng As Range Set Rng = ActiveDocument.Bookmarks("SomeBookmark").Range With Rng .Text = TextBox1.Text .Font.Bold = True End With ActiveDocument.Bookmarks.Add "SomeBookmark", Rng
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
This is the error i get
what am i doing wrong? |
#4
|
||||
|
||||
That doesn't show an error, which would be indicated by yellow highlighting and an error message, but a breakpoint.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
picture attached
|
#6
|
||||
|
||||
And what is the error message you're getting?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Run-Time error '424
Object required |
#8
|
||||
|
||||
I am unable to replicate that error with the kind of code I gave you. See attached. It would seem there is something somewhere else in your project that is having an adverse effect.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
I am a novice user to VBA. With the code you supplied, what needs to be changed? just the text in red?
Dim Rng As Range Set Rng = ActiveDocument.Bookmarks("SomeBookmark").Range With Rng .Text = TextBox1.Text .Font.Bold = True End With ActiveDocument.Bookmarks.Add "SomeBookmark", Rng |
#10
|
|||
|
|||
Here is the link to the file:
|
#11
|
||||
|
||||
From looking at your images, you'd also have to change the 'textbox1' reference. The first one had that change, but for some reason you undid that change before posting the second image.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
SOLVED
I got it to work... Thank you very much for the help Paul. Much obliged Last edited by gurp99; 03-12-2012 at 04:07 PM. Reason: Solved |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word Visual Basic error - run time error 504 | crazymorton | Word | 11 | 01-13-2012 04:32 AM |
Visual Basic Editor changes from 2003 to 2007 | Rockitman31 | Word VBA | 4 | 09-21-2011 12:01 PM |
Basic user needs drop down menus | Mabozar | Word | 1 | 01-19-2010 02:49 PM |
Referencing Tables in Visual Basic Editor | DavidB | Word Tables | 0 | 09-21-2009 04:01 PM |
A little Visual Basic Help Please | leroytrolley | Excel | 4 | 08-22-2008 03:57 AM |