View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel[_317_] joel[_317_] is offline
external usenet poster
 
Posts: 1
Default Reset QueryTable error on empty text file


I added a test for file size in the code below


Sub testQuery()

Set fs = CreateObject("Scripting.FileSystemObject")

On Error GoTo errorHandler
Dim newSheet As Worksheet
Dim Filename As String
Filename = "file.CSV"
Set f = fs.getfile(Filename)
If f.Size = 0 Then Exit Sub


Set newSheet = Sheets.Add
newSheet.Name = "test"

With newSheet.QueryTables.Add(Connection:="TEXT;" & Filename, _
Destination:=newSheet.Range("A1"))
Name = "test"
FieldNames = False
RowNumbers = False
FillAdjacentFormulas = False
PreserveFormatting = True
RefreshStyle = xlInsertDeleteCells
SavePassword = False
SaveData = True
AdjustColumnWidth = True
RefreshPeriod = 0
TextFilePromptOnRefresh = False
TextFileStartRow = 1
TextFileParseType = xlDelimited
TextFileTextQualifier = xlTextQualifierDoubleQuote
TextFileConsecutiveDelimiter = False
TextFileTabDelimiter = False
TextFileSemicolonDelimiter = False
TextFileCommaDelimiter = True
TextFileSpaceDelimiter = False
TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1,
1)
Refresh BackgroundQuery:=False
End With
Exit Sub
If newSheet.Range("A1").Value2 = "" Then MsgBox ("Cell is blank")
newSheet.Delete

errorHandler:
MsgBox prompt:=Err.Description, Title:=Err.Number
Exit Sub
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=160662

Microsoft Office Help