briancoats
Programmer
I have inserted this code, which I found in this forum and changed to accept a passed form. It is in a module so it can be called from anywhere. None of that really matters. When I had the fontsize = 7 on my list box, it worked beautifully. I set the size back to 8, nad the hscroll doesnt go all the way to the end of the code. Any ideas why this would be. Strongm posted the original code that I ripped off. (At least I give credit when it is due.)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const LB_SETHORIZONTALEXTENT = &H194
Public Sub AddAndModifyHScroll(lst As ListBox, frm As Form)
' depends on the scalewidth
' if scalemode is Twips then Divide MaxWidth by TwipsPerPixel to get pixels
Dim lp As Long
Dim MaxWidth As Long
For a = 0 To lst.ListCount - 1
If frm.TextWidth(lst.List(a)) > MaxWidth Then MaxWidth = frm.TextWidth(lst.List(a))
Next
SendMessage lst.hwnd, LB_SETHORIZONTALEXTENT, MaxWidth / Screen.TwipsPerPixelX, 0
End Sub
Brian
"Give a man a fish and you feed him for a day. Teach him to fish and you feed him for a lifetime."
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const LB_SETHORIZONTALEXTENT = &H194
Public Sub AddAndModifyHScroll(lst As ListBox, frm As Form)
' depends on the scalewidth
' if scalemode is Twips then Divide MaxWidth by TwipsPerPixel to get pixels
Dim lp As Long
Dim MaxWidth As Long
For a = 0 To lst.ListCount - 1
If frm.TextWidth(lst.List(a)) > MaxWidth Then MaxWidth = frm.TextWidth(lst.List(a))
Next
SendMessage lst.hwnd, LB_SETHORIZONTALEXTENT, MaxWidth / Screen.TwipsPerPixelX, 0
End Sub
Brian
"Give a man a fish and you feed him for a day. Teach him to fish and you feed him for a lifetime."