Thanks Rory. I want to say that this was originally coded in 2013 version. I was just upgraded to MS365 as one of the guinea pigs., cough, testers when this issue showed up.
Posts by FeedTheChunk
-
-
Here's the code copied into a clean workbook. I'm no programmer but I do try and comment my code. Not sure if the comments will help any or not.
-
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.
-
Roy, I would prefer not to. The class definition is in my personal.xlsb file that has things in there that I would prefer that it not get put into the wild.
-
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'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?
Code
Display MoreSet oTextBox = frmAdvMsgBox.Controls.Add("Forms.TextBox.1", "MsgTxt") ' Create a new Control. ' Set {object} = Form.Controls.Add(Type of control , Ctrl Name) colTextBox.Add oTextBox ' Add the control to our collection so that we can kill, remove, it when we're done ' ########################################################## ' Parse aArray(i) for all SET tags ' ########################################################## For j = 0 To UBound(aSetTags) If FindTagInString(aArray(i), aSetTags(j)) Then ' Set the font flags if we find a SET tag in the string ' This allows the Font.{property} to be 'persistant' through each n times through the loop Select Case aSetTags(j) Case "" ' Bold bBoldFlag = True Case "" ' Italic bItalFlag = True Case "" ' Strike through bStriFlag = True Case "" ' Under the Line bUndeFlag = True Case Else End Select End If Next j Debug.Print "Bold Property is : " & oTextBox.Font.Bold Debug.Print "Bold Flag is : " & bBoldFlag oTextBox.Font.Bold = bBoldFlag ' All flags default to FALSE Debug.Print "Bold Property is now: " & oTextBox.Font.Bold Debug.Print vbCrLf & "Bold Property is : " & oTextBox.Font.Bold Debug.Print "Bold Flag fored to FALSE: " & False oTextBox.Font.Bold = False ' All flags default to FALSE Debug.Print "Bold Property is now : " & oTextBox.Font.Bold oTextBox.Font.Italic = bItalFlag ' VBA7 <-- These properties get set to TRUE regardless if b{property}Flag is FALSE oTextBox.Font.StrikeThrough = bStriFlag oTextBox.Font.Underline = bUndeFlag ' Workaround would be: ' if bBoldFlag then oTextBox.Font.Bold = True Immediate Window Bold Property is : False Bold Flag is : False Bold Property is now: True Bold Property is : True Bold Flag fored to FALSE: False Bold Property is now : True Sorry about the formating. New to this and not sure how to fix it. I added in some debug.print statements to try and illustrate what is happening.
-
Thanks. I must thinking of VB. I'm sure I used to overload functions in some language that's stuck in my thick head. :p
-
Can you overload functions in VBA? I thought you could but I'm getting the ambiguous name error. I have two functions:
Function FindTableSheet(strTableName as String) as String
' code here
End Function
Function FindTableSheet (strTableName as String, ByRef strShName as String) as boolean
' code here
End function
I'm typing this in on a tablet so I may have missed typed something there. Both functions search active workbook sheets for the given strTableName. The first function returns the sheet name if it finds a table by the name in strTableName. The second one does the same but returns true if if find the table and false if it doesn't. Set strShName to the Sheet.name on success or vbNullChar on failure.
Maybe I have my languages mixed up but I thought this was legal. Thanks. Chunk.