Automation to Import Tab-Delimited Output File into Excel:   Return to List

' Remember to set a reference to the most current version of Microsoft Excel (under Tools | References within the VBE, and also that debugging must be set for "Break on Unhandled Errors"

Private Sub cmdImportToExcel_Click()
Dim ExcelApp As Object
On Error GoTo APPLICATION_CREATE' An error will cause us to initiate the Appl.
Set ExcelApp = GetObject(, "Excel.Application")
GoTo SKIP_APPLICATION_CREATE' Of course if it's already there, then we'll use that
APPLICATION_CREATE:
Set ExcelApp = CreateObject("Excel.Application")
SKIP_APPLICATION_CREATE:
On Error GoTo BYE' Back to our normal way of life
Dim myArray()
For i = 1 To intColumns
    ReDim Preserve myArray(i)
    myArray(i) = Array(i, 2)
Next
Application.StatusBar = ". . . . . . . . . . . . . . . IMPORTING INTO EXCEL !! . . "
ExcelApp.Workbooks.OpenText FileName:=MyFinalPathFile, _
    Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _
    :=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _
    False, Comma:=False, Space:=False, Other:=False, FieldInfo:=myArray()
ColumnString = "A:" & ConvertColumnNumberToLetter(intColumns)
ExcelApp.Columns(ColumnString).EntireColumn.AutoFit
ExcelApp.Range("A1").Select
ExcelApp.Visible = True
Application.StatusBar = ""
BYE: End Sub

See also:
Automating Database Compaction (every 5 times)
Automating Multiple Applications
Automating Access (Reports)
Automating Internet Explorer from Excel
Outlook Automation from within Excel
Powerpoint Automation (complex!) from within Excel
Word Automation from Excel
Automating Outlook (send email via code)
Determining File Association (uses API)
Excel chart creation through Automation
Outlook Automation
Automation of Word (getting or starting Word)



Note to Webmaster