Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with Access Import CSV file into Excel

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I created a CSV file that I want to import into Excel for easier viewing. I'm getting an error on the RED line,
error is
Object Variable or With block variable not set.
I used Excel to create the macro code.
here is my code
Code:
    Dim oApp As Excel.Application

    Set oApp = CreateObject("Excel.Application")
    oApp.Visible = True
  
    [COLOR=red]With oApp.ActiveSheet.QueryTables.Add(Connection:="TEXT;F:\TimeSheet2\OHCPay20080204.csv", Destination:=Range("A1"))[/color]
        .Name = "OHCPay20080204"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With

    Set oApp = Nothing

DougP
 



Doug,

As a VBA question, you need to post any further question in Forum707.

oApp.ActiveSheet

Excel Object Model...
[tt]
Application
Workbook
Worksheet
[/tt]
you have no workbook object.

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top