Consulting

Results 1 to 9 of 9

Thread: Toggle bold button

  1. #1

    Toggle bold button

    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.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Let's see the code to see why it does what you describe.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Mar 2005
    Location
    Helena, MT
    Posts
    90
    Location
    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

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This works for me

    [vba]

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

    With Target.Font

    .Bold = Not .Bold
    End With

    Cancel = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Quote Originally Posted by xld
    This works for me
    Are you sure? And when part of the text in a cell is bolded?

    My proposal:[vba]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[/vba]
    Artik

  6. #6
    Mr. Artik
    I don't understand these lines of your code

    [VBA]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[/VBA]
    How could I get a message box?
    I tried to double click in an empty cell but I got nothing

  7. #7
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Quote Originally Posted by YasserKhalil
    Mr. Artik
    I'm Artik, not Mr. Artik.
    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 nothing
    After double click type something in the cell. You will receive bolded text or not.

    Artik

  8. #8
    That's perfect Artik
    Thank you very much..You are brilliant

  9. #9
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Sometimes only.

    Artik

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •