AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 1,835
- Office Version
- 2019
- 2016
- Platform
- Windows
Can anyone suggest a fix or workaround, please?
In Properties label1 Autosize= True, Len = 250, Wordwrap = True
Font is ms sans serif, 8, not Bold.
I've remmed out the .Additem list bits as they're not affected. The label is the problem, in Excel 2003 it will resize to the right length
i.e. whatever text is assigned to it, but Excel2007 stays at a set width and never changes.
In Properties label1 Autosize= True, Len = 250, Wordwrap = True
Font is ms sans serif, 8, not Bold.
Code:
Sub stringtest2()
Dim LongString As String, LabelWidth As Long, ListHeight As Long
Dim NextSpacePosition As Integer, PreviousPlace As Integer, Done As Boolean
LongString = [Any text about 70 chars+ with space(s)]
UserForm3.ListBox1.Width = 250
Do
UserForm3.Label1 = LongString
LabelWidth = UserForm3.Label1.Width
If LabelWidth > 250 Then
Do
PreviousPlace = NextSpacePosition
NextSpacePosition = InStr(PreviousPlace + 1, LongString, " ")
UserForm3.Label1 = Left(LongString, NextSpacePosition)
Loop Until UserForm3.Label1.Width > 250
'UserForm3.ListBox1.AddItem Left(LongString, PreviousPlace)
LongString = Mid(LongString, PreviousPlace + 1)
NextSpacePosition = 0
Else
Done = True
End If
Loop Until Done
'UserForm3.ListBox1.AddItem LongString
ListHeight = UserForm3.ListBox1.ListCount * 10
UserForm3.ListBox1.Height = ListHeight
UserForm3.Show vbModeless
End Sub
I've remmed out the .Additem list bits as they're not affected. The label is the problem, in Excel 2003 it will resize to the right length
i.e. whatever text is assigned to it, but Excel2007 stays at a set width and never changes.