Sub ProcessGCodeFile()
Dim X As Long, Z As Long, FileNum As Long, Index As Long
Dim TotalFile As String, PathFile As String
Dim NLines() As String, Gspaced() As String, LinesOut() As String
Const MaxPossibleGCodesPerLine As Long = 20
If ActiveSheet.UsedRange.Cells.Count = 1 And Len(ActiveSheet.UsedRange.Cells(1).Value) = 0 Then
MsgBox "The active worksheet must be totally empty..." & vbLf & _
"I see data on the currently active sheet", vbCritical
Exit Sub
End If
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Show
On Error GoTo NoFileSelected
PathFile = .SelectedItems(1)
End With
FileNum = FreeFile
Open PathFile For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
NLines = Split(Replace(TotalFile, "G00", "N G00", , 1), vbNewLine & "N")
ReDim LinesOut(1 To UBound(NLines), 1 To MaxPossibleGCodesPerLine)
For X = 1 To UBound(NLines)
Gspaced = Split(Split(NLines(X), vbNewLine)(0))
Index = 0
For Z = 0 To UBound(Gspaced)
Index = Index + 1
LinesOut(X, Index) = Mid(Gspaced(Z), 2 + (Z = 0))
Next
Next
Range("A1").Resize(UBound(LinesOut), UBound(LinesOut, 2)) = LinesOut
NoFileSelected:
End Sub