Created
August 21, 2012 14:25
-
-
Save cgorshing/3415982 to your computer and use it in GitHub Desktop.
Read Fixed Width File w/Excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'This script was based almost entirely on http://blogs.technet.com/b/heyscriptingguy/archive/2008/04/14/how-can-i-import-a-fixed-width-data-file-into-microsoft-excel.aspx | |
Const xlFixedWidth = 2 | |
'http://msdn.microsoft.com/en-us/library/office/bb241018(v=office.12).aspx | |
Const xlDMYFormat = 4 ' DMY date format. | |
Const xlDYMFormat = 7 ' DYM date format. | |
Const xlEMDFormat = 10 ' EMD date format. | |
Const xlGeneralFormat = 1 ' General. | |
Const xlMDYFormat = 3 ' MDY date format. | |
Const xlMYDFormat = 6 ' MYD date format. | |
Const xlSkipColumn = 9 ' Column is not parsed. | |
Const xlTextFormat = 2 ' Text. | |
Const xlYDMFormat = 8 ' YDM date format. | |
Const xlYMDFormat = 5 ' YMD date format. | |
Set objExcel = CreateObject("Excel.Application") | |
objExcel.Visible = True | |
' The 3 says to start on the third line | |
' objExcel.Workbooks.OpenText <filename>,,3,xlFixedWidth,,,,,,,,, _ | |
objExcel.Workbooks.OpenText WScript.Arguments(0),,,xlFixedWidth,,,,,,,,, _ | |
Array(_ | |
Array(0, xlTextFormat),_ | |
Array(6, xlGeneralFormat),_ | |
Array(15, xlGeneralFormat),_ | |
Array(25, xlGeneralFormat),_ | |
Array(27, xlGeneralFormat),_ | |
Array(31, xlGeneralFormat),_ | |
Array(35, xlGeneralFormat),_ | |
Array(36, xlGeneralFormat),_ | |
Array(61, xlGeneralFormat),_ | |
Array(86, xlGeneralFormat),_ | |
Array(87, xlGeneralFormat),_ | |
Array(107, xlGeneralFormat),_ | |
Array(127, xlGeneralFormat),_ | |
Array(147, xlGeneralFormat),_ | |
Array(149, xlGeneralFormat),_ | |
Array(159, xlGeneralFormat),_ | |
Array(170, xlGeneralFormat),_ | |
Array(180, xlGeneralFormat),_ | |
Array(190, xlGeneralFormat),_ | |
Array(191, xlGeneralFormat),_ | |
Array(192, xlGeneralFormat),_ | |
Array(194, xlGeneralFormat),_ | |
Array(195, xlGeneralFormat),_ | |
Array(197, xlGeneralFormat),_ | |
Array(198, xlGeneralFormat),_ | |
Array(208, xlGeneralFormat),_ | |
Array(210, xlGeneralFormat),_ | |
Array(212, xlGeneralFormat),_ | |
Array(220, xlGeneralFormat),_ | |
Array(222, xlGeneralFormat),_ | |
Array(224, xlGeneralFormat),_ | |
Array(232, xlGeneralFormat),_ | |
Array(233, xlGeneralFormat),_ | |
Array(243, xlGeneralFormat),_ | |
Array(249, xlGeneralFormat),_ | |
Array(250, xlGeneralFormat),_ | |
Array(270, xlGeneralFormat),_ | |
Array(290, xlGeneralFormat),_ | |
Array(298, xlGeneralFormat),_ | |
Array(302, xlGeneralFormat),_ | |
Array(306, xlGeneralFormat),_ | |
Array(310, xlGeneralFormat),_ | |
Array(315, xlGeneralFormat),_ | |
Array(320, xlGeneralFormat),_ | |
Array(330, xlGeneralFormat),_ | |
Array(331, xlGeneralFormat)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment