'this sub splits the file Sub Split() Dim tFile As String Dim tPath As String Dim tSplitFile As String Dim tChunk As Single Dim Txt As String Dim n As Long, nLength As Long Dim m As Long Dim Finished As Boolean 'get user input tFile = Range("Filename") tChunk = Range("Chunk") 'check source file exists On Error Resume Next If Dir(tFile) = "" Then MsgBox "I can't find the file. Please specify the full path and name", vbExclamation Exit Sub End If On Error GoTo 0 'initialise tPath = Left$(tFile, InStrRev(tFile, "\")) nLength = FileLen(tFile) '+ 1 'delete any existing split files n = 0 Do n = n + 1 tSplitFile = tPath & "Split" & n & ".dat" If Dir(tSplitFile) <> "" Then Kill tSplitFile Else Exit Do Loop 'do the split n = 0 Open tFile For Binary As #1 Do 'the last chunk will be what's left over... m = nLength - n * tChunk If m > tChunk Then m = tChunk Else 'last chunk, mark as finished Finished = True End If 'set up dummy string of correct length & read in data Txt = String(m, " ") Get #1, , Txt 'write to file n = n + 1 tSplitFile = tPath & "Split" & n & ".dat" Open tSplitFile For Binary As #2 Put #2, , Txt Close #2 Loop While Not Finished Close #1 'test result - True parameter tells Excel this is a test only If CombineSplits(True) Then MsgBox "The file has been split successfully" End Sub 'combines files - triggered by user click Sub Combine() CombineSplits End Sub 'combines files 'Testing parameter tells Excel if this is a test only Function CombineSplits(Optional Testing As Boolean = False) As Boolean Dim tFile As String Dim tFile0 As String Dim tPath As String Dim tChunk As Single Dim Txt As String Dim n As Long, nLength As Long Dim m As Long 'if testing, create a dummy filename to put the results into If Testing Then tFile0 = Range("Filename") 'actual original filename n = InStr(tFile0, ".") - 1 tFile = Left$(tFile0, n) & "_a" & Mid$(tFile0, n + 1) 'dummy filename tChunk = Range("Chunk") Else 'we're combining for real, watch out if file exists already tFile = Range("Filename") If Dir(tFile) <> "" Then If MsgBox("The filename you have specified exists already. Do you want to overwrite it", vbQuestion + vbYesNo) <> vbYes Then Exit Function End If End If End If tPath = Left$(tFile, InStrRev(tFile, "\")) 'do the combining n = 0 Open tFile For Binary As #1 Do n = n + 1 Txt = Dir(tPath & "Split" & n & ".dat") If Txt = "" Then Exit Do Txt = String(FileLen(tPath & "Split" & n & ".dat"), " ") Open tPath & "Split" & n & ".dat" For Binary As #2 Get #2, , Txt Close #2 Put #1, , Txt Loop Close #1 If n = 1 Then MsgBox "I didn't find any files to combine", vbExclamation Exit Function End If 'if testing, compare dummy result with original, bye by byte If Testing Then Dim b1() As Byte, b2() As Byte FilesBinaryRead tFile0, b1() FilesBinaryRead tFile, b2() 'kill dummy file Kill tFile For n = 1 To UBound(b1) If b1(n) <> b2(n) Then MsgBox "The split failed at byte " & n Exit Function End If Next n CombineSplits = True Else MsgBox "The files have been recombined" CombineSplits = True End If End Function Sub FilesBinaryRead(ByVal sFileName As String, ByRef bb() As Byte) Dim ihwndFile As Integer 'Open file ihwndFile = FreeFile Open sFileName For Binary Access Read As #ihwndFile 'Size the array to hold the file contents ReDim bb(1 To LOF(ihwndFile)) Get #ihwndFile, , bb Close #ihwndFile End Sub