+ Reply to Thread
Results 1 to 5 of 5

CSV empty file causing an error

Hybrid View

  1. #1
    Registered User
    Join Date
    01-20-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    30

    CSV empty file causing an error

    I have a csv import on my spreadsheet and it throws an error if the csv file is empty (error 7 out of memory). Is there any way to check if the file is empty and just abort the macro? (or something else, maybe a popup error so know what is going on).

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: CSV empty file causing an error

    Just opening an empty csv file won't cause an error, so I suspect that there is more to it. Can you upload your worksheet? Or post the section of code which seems to be causing this error?

  3. #3
    Registered User
    Join Date
    01-20-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: CSV empty file causing an error

    Also although it has "refresh background query" set to false... it gives a "warning this is linked to other spreadsheets" error when you open it.

  4. #4
    Registered User
    Join Date
    01-20-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: CSV empty file causing an error

    Sub CSVimport()
    '
    ' CSVimport Macro
    '
        With Worksheets("CSV")
                .Visible = xlSheetVisible
                .Activate
                .Range("A1").Select
            End With
        Sheets("CSV").Select
        ActiveSheet.columns("A:C").Select
        Selection.ClearContents
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;E:\Work\current.csv", _
            Destination:=Range("$A$1"))
            .Name = "current"
            .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 = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = True
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        Sheets("Active").Select
        Worksheets("CSV").Visible = xlSheetVeryHidden
    End Sub

  5. #5
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: CSV empty file causing an error

    I got an error on the line:

    .Refresh BackgroundQuery:=False
    With both an empty csv file and a none-empty csv file.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1