ZIP files make "Strict Parse Error" in Excel VBA QueryTables - I think

wipedaler

New Member
Joined
Feb 14, 2007
Messages
4
Environment: Excel 2010 in Windows 7
Question: Can QueryTables gracefully handle encountering a .zip file when expecting .txt?

We have a database of text-based information logs from a large number of machines. The log files are stored as the same file name, but located in a folder path that looks like /someServer/machineID/dateFolder/logfile, where dateFolder is simply the fiscal week + day + year, and logfile is usually* a text file. [ * for some of the older log files, I am finding that the file format is .zip ]

I am using Excel to do the following:
- take input of a unique ID from the user; machineID is typed in an input cell
- determine the latest dateFolder using other information in the machineID folder (this is reliable as long as machineID is found - not a problem)
- construct the 'source' file path to the latest log file (OK so far)
- pull the text from the file located at that path, using ActiveSheet.QueryTables.Add

When the logfile is text, this method has been working very well. Occasionally when the logfile is a zip file, the destination cell would have garbage in it, and I know that that log file is compressed, so I move on or take other action.

Recently, when the logfile is a zip file (confirmed by browsing that file path and inspecting the file), the VBA will stop with a "Strict Parse Error". The error box image is linked here.
parse_error.jpg


The contents of that log file are:
Code:
XML PARSE ERROR:  Malformed or illegal tag name
  Error occurs at or below this element stack:
    (Stack is empty--error occurs at or below top-level element.)

The VBA code segment that is executing when I get this error is:
Code:
' FIRST, identify the date (folder path) for the most recent sweep
    theURL = baseURL & sysID & lastCheck
'
' << then there is a section of code that works well to determine the right path >>
'
' SECOND, go and get the data from the healthCheck log file in the destination directory
    
    ' clear the destination cell
    Range("A1").ClearContents
    
    With ActiveSheet.QueryTables.Add(Connection:= _
    theURL _
    , Destination:=Range("A1"))
        .Name = "IRIS_data"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = False  ' was True
        .RefreshOnFileOpen = False
        .BackgroundQuery = False     ' was True
        .RefreshStyle = xlOverwriteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False     ' was True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = True     ' was False
        .Refresh BackgroundQuery:=False
    End With


GOAL: I would like to find a way to at least gracefully manage this error, notify the user (or write a 'problem' tag) and finish the code.
A bonus would be to (a) recognize that the destination file is a zip file, (b) decompress the file to text, (c) load the text into the output field as if the source had been text, and (d) clean up any saved zip or txt files on the hard drive. { I saw some examples of code to work with zip's at http://www.rondebruin.nl/windowsxpunzip.htm }

Many thanks for any suggestions to resolve the primary problem of the Error. This code may be rather crude; I'm not a programmer by training. We use VBA as a tool to help simplify and speed the work we do, so sometimes 'functional' is good enough. Best regards!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top