Hi , I downloaded a sample file from the net which is a simple example of using ListView in excel. Next, I found a script about how to autofit the columns in the ListView. However, I dont know how to insert correctly the script so that the ListView Control could autofit all its columns. Could anyone help pls?
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const LVM_FIRST = &H1000
Public Sub LV_AutoSizeColumn(LV As ListView, Optional Column _
As ColumnHeader = Nothing)
Dim C As ColumnHeader
If Column Is Nothing Then
For Each C In LV.ColumnHeaders
SendMessage LV.hWnd, LVM_FIRST + 30, C.Index - 1, -1
Next
Else
SendMessage LV.hWnd, LVM_FIRST + 30, Column.Index - 1, -1
End If
LV.Refresh
End Sub
Bookmarks