I decided to approach the problem a little differently. Instead of trying to rebuild the Mod function to handle numbers > 2,147,483,648, I went back to the initial problem, i.e., converting from decimal to binary, broke the initial value into manageable pieces, processed each piece and then added up the binary results. Seems to work. 2 billion seemed like a reasonable "chunk", so that is the building block. Could be any other number less than 2,147,483,648.
I have only done a little testing, but it seems to hang together. There are probably more elegant ways to do this, but ...
Sub Dec2Bin_Test()
Dim N As Variant
Dim strN As String
strN = InputBox(" Dec2Bin: Initial decimal value?")
If strN = vbNullString Then Exit Sub
N = CDec(strN)
MsgBox "[decimal] " & strN & " = [binary] " & Dec2Bin(N)
End Sub
Function Dec2Bin(DecNum As Variant) As String
Dim Count As Long
Dim I As Long
Dim N As Variant
Dim Ntemp As Long
Dim strTemp As String
Dim strBin2B As String
strBin2B = "1110111001101011001010000000000"
Dec2Bin = "error encountered"
N = CDec(DecNum)
Again:
If N < 2000000000 Then
Ntemp = N
Do While Ntemp <> 0
strTemp = Trim(Str(Ntemp Mod 2)) & strTemp
Ntemp = Ntemp \ 2
Loop
Dec2Bin = strTemp
For I = 1 To Count
Dec2Bin = BinAdd(Dec2Bin, strBin2B)
Next I
Exit Function
Else
N = N - 2000000000
Count = Count + 1
GoTo Again
End If
End Function
Function BinAdd(Bin1 As String, Bin2 As String) As String
Dim Adder As Long
Dim I As Long
Dim LenMax As Long
Dim Sum As Long
Dim TempBin As String
LenMax = Len(Bin1)
If Len(Bin2) > LenMax Then LenMax = Len(Bin2)
Adder = 0
For I = 1 To LenMax
Sum = 0
If I <= Len(Bin1) Then Sum = Sum + CInt(Mid(Bin1, Len(Bin1) - I + 1, 1))
If I <= Len(Bin2) Then Sum = Sum + CInt(Mid(Bin2, Len(Bin2) - I + 1, 1))
Sum = Sum + Adder
Select Case Sum
Case Is = 0
TempBin = TempBin & "0"
Adder = 0
Case Is = 1
TempBin = TempBin & "1"
Adder = 0
Case Is = 2
TempBin = TempBin & "0"
Adder = 1
Case Is = 3
TempBin = TempBin & "1"
Adder = 1
Case Else
MsgBox "error. sum value = " & Sum
BinAdd = "error encountered"
Exit Function
End Select
Next I
If Adder = 1 Then TempBin = TempBin & "1"
BinAdd = StrReverse(TempBin)
End Function