View Full Version : Selection.Font.Bold = True doesn't work
vaxim
01-10-2009, 02:48 AM
I tried use VBA to bold a selected word in MS Word. The code is ...
Selection.Font.Bold = True
However, this doesn't work. I also tried
Selection.Font.Bold = wdToggle
And this doesn't work also. Please help.
macropod
01-10-2009, 03:52 AM
Hi vaxim,
It works for me. What version of Word are you using? Are macros enabled?
vaxim
01-10-2009, 06:26 AM
dear macropod
I use Word 2003 and I think macro is enabled because I can run other VBA script.
lucas
01-10-2009, 10:13 AM
You have to actually select some text vaxim......manually or with code.
Just having the cursor in the line will not work.
vaxim
01-10-2009, 06:12 PM
I tried
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Font.Bold = True
But the selected text was not bold.
macropod
01-10-2009, 11:22 PM
Hi vaxim,
With your latest code, all that gets the bold font is the string from the right of the insertion point until the end of the word in which the insertion point in located, plus the following puntuation character. For example, with the text "The quick brown fox jumps over the lazy dog.", if the insertion point is between the 'w' and 'n' in 'brown', all that gets the bold font is the 'n '. If the insertion point is after the 'n' in 'brown', all that gets the bold font is the ' ' and, if the insertion point is beyween the ' ' and 'b' in 'brown', what gets the bold font is 'brown '.
Perhaps you could explain what you're trying to do.
vaxim
01-11-2009, 01:05 AM
Hi Macropod
Thank you for your reply. I tested the lastest macro in this thread with the string "the quick brown ..." The result is the same as you said. However, when I tested with the string in Thai language, the macro cannot bold any word at all.
Fortunately, now I know a solution to this problem. I changed
Selection.Font.Bold = True
to
Selection.Font.BoldBi = True
And the macro can bold a Thai word. :beerchug:
fumei
01-12-2009, 12:58 PM
.Bold applies to left-to-right languages.
The BoldBi property applies to text in a right-to-left language.
Note that BoldBi also applies to the Range object in right-to-left languages. It applies to the color index (Font.ColorIndexBi). It applies to italics (Font.ItalicsBi; Range.Font.ItalicsBi) and all the format properties, such as Font.SizeBi.
dc4life78
01-21-2009, 07:51 AM
Have you defined your Word application object? Otherwise Selection by itself would be ambiguous to VB. For example:
Dim oWord As Word.Application
Set oWord As New Word.Application (or the name of your existing file)
Once you have that then you can select the desired text either manually or with the code and do:
oWord.Selection.Font.Bold = True
fumei
01-21-2009, 11:18 AM
Huh?
1. What makes you think there is any need for an explicit application object? The OP never mentions VB, or actioning Word from any other application.
The OP wrote: "I tried use VBA to bold a selected word in MS Word."
Therefore they ARE in Word. There is no need for an oWord As Word.Application.
2. The OP does mention that they are using Thai language.
Fortunately, now I know a solution to this problem. I changed
Selection.Font.Bold = True
to
Selection.Font.BoldBi = True
And the macro can bold a Thai word.
The reason .BoldBi does work (and .Bold does not) is BECAUSE it is Thai. .Bold will never work - with or without an properly defined application object - on a right-to-left language.
All format properties require the use of Bi for these languages.
.SizeBi
.BoldBi
.ItalicsBi
etc.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.