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.
The contents of that log file are:
The VBA code segment that is executing when I get this error is:
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!
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.
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!