Importing Hercules CSV Data Into Excel

advertisement
Importing Hercules CSV Data Into Excel
When importing Hercules GMLAN buffer files into Excel, Excel (mis)interprets any 11 bit frame ID with an "E" in it
as scientific notation. Hence, frame $1E9 ends up being 1.00E+09, or frame $1E5 is imported as 1.00E+05. There
are two ways to suppress the auto-number convert feature on import and force Excel to do a straight text import.
The first way – If you don't want to use macros:
1. Rename the file from *.CSV to *.TXT. Note: this is not the same as saving a buffer from Hercules with the
.txt extension.
2. Open the file. The .txt extension forces excel to use the import wizard.
3. Set the data type to delimited.
4. Check the delimiter type "Comma" and remove the check next to the "Tab" box.
1
5. Scroll down in the data preview window and highlight the "Frame ID" and "Frame Acronym" columns, then
change their associated "Column data format" from "General" to "Text". The file will then import correctly.
The second way – using macros:
Rename the file from *.CSV to *.TXT. This will bring up the Text Import wizard, and you can select the format for
each column in the file. Here's a macro function that will open the (renamed) file:
Sub Import_Herc_TXT_File()
Workbooks.OpenText Filename:="C:\272BenchRunning.txt", DataType:=xlDelimited,
Comma:=True, _
FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5,
2), _
Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2))
End Sub
Import the Data into Active Worksheet. Using the "Data / Get External Data / Import Text File" menu option, you
can import the CSV and format the columns without renaming the file. Here's a macro function that opens the
unrenamed example file (tip, uncommenting the first line will import the data to a blank sheet in the
activeworkbook):
Sub Import_Herc_CSV_File()
' ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\272BenchRunning.csv",
Destination:=Range("A1"))
.Name = "272BenchRunning"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
2
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2)
.Refresh BackgroundQuery:=False
End With
End Sub
Dearborn Group, Inc.
(248) 488-2080 | (248) 488-2082 FAX | dg@dgtech.com
3
Download