WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Import a text file into an Excel Column

 Keywords: Import text txt file Excel Column 

;Import a text file into an Excel Column


excelfile = "C:\Temp\Data\Sample.xls"
connectionstring = "TEXT;C:\temp\test.txt" ;file to import
dest_range = "A1"

;define constants
xlInsertDeleteCells = 1
xlDelimited = 1
xlTextQualifierDoubleQuote = 1

;	Start excel here
objxls = objectopen("Excel.Application")
objxls.visible = @true
objwrkbks = objxls.workbooks


objwrkbks.open (excelfile)
objactsheet = objxls.activesheet
objrange = objxls.Range(dest_range)
objquerytables = objactsheet.QueryTables
objquerytable = objquerytables.Add(::Connection = connectionstring, Destination = objrange)
objquerytable.Name = "test"
objquerytable.FieldNames = @True
objquerytable.RowNumbers = @False
objquerytable.FillAdjacentFormulas = @False
objquerytable.PreserveFormatting = @True
objquerytable.RefreshOnFileOpen = @False
objquerytable.RefreshStyle = xlInsertDeleteCells
objquerytable.SavePassword = @False
objquerytable.SaveData = @True
objquerytable.AdjustColumnWidth = @True
objquerytable.RefreshPeriod = 0
objquerytable.TextFilePromptOnRefresh = @False
objquerytable.TextFilePlatform = 437
objquerytable.TextFileStartRow = 1
objquerytable.TextFileParseType = xlDelimited
objquerytable.TextFileTextQualifier = xlTextQualifierDoubleQuote
objquerytable.TextFileConsecutiveDelimiter = @True
objquerytable.TextFileTabDelimiter = @False
objquerytable.TextFileSemicolonDelimiter = @False
objquerytable.TextFileCommaDelimiter = @False
objquerytable.TextFileSpaceDelimiter = @True
objquerytable.TextFileTrailingMinusNumbers = @True
objquerytable.Refresh(::BackgroundQuery = @False)		


objxls.quit
objectclose(objquerytable)
objectclose(objquerytables)
objectclose(objactsheet)
objectclose(objwrkbks)
objectclose(objxls)



Article ID:   W15635
File Created: 2003:05:13:11:29:20
Last Updated: 2003:05:13:11:29:20