Here is a copy of my code thus far:
Private Type POINTAPI
x As Long
y As Long
End Type
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias
"GetTextExtentPoint32A" (ByVal hDC As Long, ByVal lpsz As String, ByVal
cbString As Long, lpSize As POINTAPI) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As
Long
Public Sub AddItemToListBox(frm As UserForm, lst As Object, itm As String)
lst.AddItem itm
Dim hwnd As Long
hwnd = FindWindow("ThunderDFrame", frm.Caption)
Dim hDC As Long
hDC = GetWindowDC(hwnd)
Dim pt As POINTAPI
GetTextExtentPoint32 hDC, itm, Len(itm), pt
Dim width As Long
If InStr(lst.ColumnWidths, " pt") 0 Then
width = Mid(lst.ColumnWidths, 1, InStr(lst.ColumnWidths, " pt") - 1)
Else
width = -1
End If
Dim newWidth As Long
newWidth = pt.x
If newWidth width Then lst.ColumnWidths = newWidth
End Sub
"Justin Starnes" wrote in message
...
Unfortunately, the problem with that solution is that I cannot accurately
determine the width of the longest string. To solve that problem, I tried
using the GetTextExtent32 function to obtain the length of the string.
Hoewver, when I set columnwidths to that value, I don't get the correct
result. ColumnWidths defaults to points for the specification. Is
GetTextExtent returning twips, pixels, etc.? I tried to convert it to
points, but am not having much luck. Any ideas?
"Robin Hammond" wrote in message
...
Just set the columnwidth to more than the width of the listbox in the
properties pane in the VBE.
Robin Hammond
www.enhanceddatasystems.com
"Justin Starnes" wrote in message
...
I have a listbox on a userform that contains entries longer than the
length of the listbox. Thus, I'm looking to add a horizontal scrollbar to
the listbox but am having trouble finding a code sample for userforms.
Does anyone have an example or can help me get one working with
userforms?
Thanks,
Justin