Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Imported text file to begin from the first empty cell p11p00 Excel Programming 3 November 1st 08 04:39 PM
Reset Delimiter when opening text file KAM Excel Programming 8 September 8th 06 01:18 PM
Saving to text file - tabs from empty cells ignored lif[_8_] Excel Programming 0 July 20th 06 04:51 PM
how to reset data entry cells to 0 or empty Bruce[_9_] Excel Programming 4 March 15th 06 02:03 AM
Changing only source file of pre-existing text import QueryTable? EBrowne Excel Programming 3 August 23rd 04 03:31 AM


All times are GMT +1. The time now is 10:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"