PDA

View Full Version : Toggle bold button



JimVABeach
08-14-2010, 04:07 PM
:hi: Hello,
Is there a way to bold and unbold a selected word or words in excel with a toggle or command button? I can do it with VBA code, but when I attach the code to the button_click event, it toggles the bold button on the format toolbar on and off. It doesn't bold the selected text.

I know I could use the format toolbar's bold button, but I'm experimenting with making my own toggle buttons. I eventually want to make more complicated toggle buttons/switches, but I'm trying to start small.

Bob Phillips
08-14-2010, 04:14 PM
Let's see the code to see why it does what you describe.

lenze
08-15-2010, 03:02 PM
Have you considered a DoubleClick??

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
If Target.Font.Bold = False Then
Target.Font.Bold = True
Else: Target.Font.Bold = False
End If
End Sub

lenze

Bob Phillips
08-15-2010, 03:42 PM
This works for me



Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

With Target.Font

.Bold = Not .Bold
End With

Cancel = True
End Sub

Artik
08-15-2010, 05:46 PM
This works for meAre you sure? And when part of the text in a cell is bolded? :)

My proposal:Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

With Target.Font
If IsNull(.Bold) Then
Select Case MsgBox("Bold all the text in a cell(s)?", _
vbQuestion + vbDefaultButton3 + vbYesNoCancel)
Case vbYes
.Bold = True
Case vbNo
.Bold = False
Case vbCancel

End Select
Else
.Bold = Not .Bold
End If
End With

Cancel = True
End Sub
Artik

YasserKhalil
08-15-2010, 05:57 PM
Mr. Artik
I don't understand these lines of your code

If IsNull(.Bold) Then
Select Case MsgBox("Bold all the text in a cell(s)?", _
vbQuestion + vbDefaultButton3 + vbYesNoCancel)
Case vbYes
.Bold = True
Case vbNo
.Bold = False
Case vbCancel

End Select
How could I get a message box?
I tried to double click in an empty cell but I got nothing

Artik
08-15-2010, 06:21 PM
Mr. Artik
I'm Artik, not Mr. Artik.:winking2:

I don't understand these lines of your code
MsgBox shows up only when part of the text in a cell is bolded.


I tried to double click in an empty cell but I got nothingAfter double click type something in the cell. You will receive bolded text or not.

Artik

YasserKhalil
08-15-2010, 06:49 PM
That's perfect Artik
Thank you very much..You are brilliant

Artik
08-15-2010, 06:54 PM
Sometimes only. ;)

Artik