VBA7 - Unable to set font property of Textbox to FALSE

  • I've created a message box class module that gives me more control over how messages are displayed. I was upgraded to MS365 and now my custom message box class doesn't work as expected.


    I'm dynamically creating textboxes and adding them to a userform. I then parse the caption to display and break out each word. Each textbox will display one word in the caption / message. Doing this allows me to set the the font properties for BOLD, Italic, Strikethrough and Underline.


    However, now when ever I attempt to change the Font.{property} it always sets it to TRUE. Can anyone explain what is going on here? Has VBA just been covering my bad programing habits and now it's coming back to haunt me?


  • The case statements didn't copy paste correctly and now it won't allow me to edit it.


    This is an example of what should happen:

    Valid tag sets:
    This is <B>Bold</B> This is Bold String ends with a tag
    <B>This</B> is Bold This is Bold String begins with a tag
    This <B>is</B> Bold This is Bold Tag contained inside String
    <B>This is Bold</B> This is Bold Tag for the entire String
    <B>This is Bold This is Bold No ReSet tag
    This is <B></B>Bold This is Bold Set/ReSet tag together
    This is B<B>old</B> This is Bold Set/ReSet tags inside word
  • I have seen this mentioned before, several years ago, where you could only set Font.Bold to True, not to False. If I remember rightly the initial issue was to do with controls in a frame (in Excel 2010), rather than directly on the userform, but someone else subsequently reported the issue with 2013 as well. I think the workaround was to use the name of the control to index into the Controls collection of the parent - something like:


    Code
    1. oTextbox.parent.controls(otextbox.name).font.bold = False


    Does that work for you?

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Immediate Window results (from line 26 - 29 above):


    Bold Property is : False

    Bold Flag is : False

    Bold Property is now: True


    Unfortunately not. As soon as it sets the bold property it changes it to true. To be clear this also happens with the italic, underline and strikethrough properties. I'll copy the class module and a little test routine that I have for testing into a clean workbook and post it in a bit. thanks for the help.

  • Using 2016 I only see True when the flag variable is True. I'll try and test in 365 later on.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why