Having nothing better to do today, I decided to do something that apparently
only Michael Kaplan knows how to do (and cannot disclose due to legal
reasons).
My method is really nothing more than a stupid cheat, embedding the whole
binary contents of the file in vba code, but who needs more? It seems to
create the file quickly and reliably and avoids using an OLE field in a
table to do this (which some people don't like). Apart from the slightly
large module size, I can't see any reason to avoid this method. Does anyone
care to comment?
Public Function CreateWorkgroup(strPath As String) As Boolean
On Error GoTo Err_Handler
Dim a(0 To 3327) As String
Dim lngCount As Long
Dim strData As String
Dim intFile As Integer
a(0) =
"000100004A65742053797374656D20444220200001000000B 56E03626009C255"
a(1) =
"E9A96772403F009C7E9F90FF859A31C57FBAED30BBDFCC9D6 3D9E4C39F46AE38"
a(2) =
"4BEE7A6DEC37A1D29CFA3AC828E6EF208A60A8027B3609E4D FB18B6213433339"
<snip><snip><snip><snip><snip><snip>
a(3327) =
"6A2EED6AD8861A1B71052B9CFACCE699FC170E04EC32CD1D8 55E70B4CF6E38D7"
For lngCount = 0 To 3327
strData = strData & ConvertHex(a(lngCount))
Next lngCount
intFile = FreeFile
Open strPath For Binary As intFile
Put intFile, , strData
Close intFile
CreateWorkgroup = True
Exit_Handler:
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Function
Private Function ConvertHex(strCode As String) As String
Dim lngPos As Long
Dim strData As String
Dim str As String
If Len(strCode) > 1 Then
If Len(strCode) Mod 2 = 0 Then
lngPos = 1
Do While lngPos < Len(strCode)
strData = strData & Chr$(CLng("&H" & Mid$(strCode, lngPos,
2)))
lngPos = lngPos + 2
Loop
End If
End If
ConvertHex = strData
End Function