Excel 2003 routine fails in Excel 2007 - Label autosize issue

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. 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.

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.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top