A small function to convert decimal integer values to a binary string. The number of bits can be optionally specified but this will be increased if insufficient.
Public Function DecToBin(DeciValue As Long, Optional NoOfBits As Integer = 8) _
As String
Dim i As Integer
Do While DeciValue > (2 ^ NoOfBits) - 1
NoOfBits = NoOfBits + 8
Loop
DecToBin = vbNullString
For i = 0 To (NoOfBits - 1)
DecToBin = CStr((DeciValue And 2 ^ i) / 2 ^ i) & DecToBin
Next i
End Function