Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
For the code below, I get the following "Run-Time error '1004'"
"Excel cannot find the text file to refresh this external data range. Check to make sure that the text file has not been moved or renamed, then try the refresh again." What I can't understand is why the code works fine when I run the program immediately after receiving the error. It works this way everytime I go to import another new text file which makes me think it might have something to do with the default file location being set after the error occurs (?). Thanks for any insights, -Tony Sub GetWFiles(Wpath As String, WhichWfile As Integer) Dim i As Long, qt As QueryTable, Wdat As String, OrigWSheet As String 'On Error Resume Next Worksheets.Add After:=Worksheets("OrigTarr") OrigWSheet = "OrigW" If WhichWfile < 1 Then OrigWSheet = OrigWSheet & CStr(WhichWfile) ActiveSheet.Name = OrigWSheet 'this is where the error occurs first time through only Wdat = Dir(Wpath & "\W*.dat") Do While Wdat = "" GetWDirectoryAgain Wpath, WhichWfile Wdat = Dir(Wpath & "W*.dat") Loop i = 0 Do While Wdat < "" i = i + 1 Cells(1, i).Value = Wdat With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;" & Wpath & Wdat, Destination:=Cells(2, i)) .Name = Left(Wdat, Len(Wdat) - 4) .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 = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With Wdat = Dir() For Each qt In ActiveSheet.QueryTables qt.Delete Next Loop End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable | Excel Discussion (Misc queries) | |||
QueryTable date problem | Excel Programming | |||
Problem:Query Cell contain Formula from QueryTable is always get old value | Excel Programming | |||
Populate QueryTable Using SQL Server - Connection Problem | Excel Programming | |||
Selection.QueryTable problem | Excel Programming |