Option Explicit
Const GWL_STYLE = -16&
Const TVM_SETBKCOLOR = 4381&
Const TVS_HASLINES = 2&
Private Sub UserForm_Activate()
SetTreeViewBackColor TreeView1, RGB(255, 0, 0)
End Sub
Sub SetTreeViewBackColor(TV As TreeView, ByVal BackColor As Long)
Dim lStyle As Long
Dim TVNode As Node
' set the BackColor for every node
For Each TVNode In TV.Nodes
TVNode.BackColor = BackColor
Next
' set the BackColor for the TreeView's window
SendMessage TV.hwnd, TVM_SETBKCOLOR, 0, ByVal BackColor
' get the current style
lStyle = GetWindowLong(TV.hwnd, GWL_STYLE)
' temporary hide lines
SetWindowLong TV.hwnd, GWL_STYLE, lStyle And (Not TVS_HASLINES)
' redraw lines
SetWindowLong TV.hwnd, GWL_STYLE, lStyle
End Sub