PC Review


Reply
Thread Tools Rate Thread

1004 error - can't find text file to refresh ...

 
 
=?Utf-8?B?TGVBbm4=?=
Guest
Posts: n/a
 
      29th Sep 2007
I have 2 procedures in a module. One imports external data (.csv) to a named
sheet (which works) then calls another procedure wthich imports a .dat file.
I'm getting the error above during the second import. I have checked using
debug.print and the file path is correct. The last line of code (.Refresh...)
is causing my problem. Here's my code. Any ideas?

Thanks
LeAnn

CODE:
Sub ImportData(strFile As String)
'

Dim strDir As String
strDir = "my network path" & strFile

With Worksheets("Result")
.Select
.Range("a1").Select
End With

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & strDir _
, Destination:=Range("Q22"))
.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 = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      29th Sep 2007
I think the problem is based on the data you are trying to import. Not sure.
Try go on spreadsheet to tools - Macro - Record Macro. Then manually import
each of the two files. On spreadsheet Menu - Data - Import External Data -
New web query. Enter in URL address the location of the two files. The URL
can be a file on your disk. Just enter c:/temp/... . Use forward slashes
instead of backward slashes. Then stop recording macro and compare the macro
for importing the two files. You can actually run the macro again to make
sure the recorded macro works properly.

"LeAnn" wrote:

> I have 2 procedures in a module. One imports external data (.csv) to a named
> sheet (which works) then calls another procedure wthich imports a .dat file.
> I'm getting the error above during the second import. I have checked using
> debug.print and the file path is correct. The last line of code (.Refresh...)
> is causing my problem. Here's my code. Any ideas?
>
> Thanks
> LeAnn
>
> CODE:
> Sub ImportData(strFile As String)
> '
>
> Dim strDir As String
> strDir = "my network path" & strFile
>
> With Worksheets("Result")
> .Select
> .Range("a1").Select
> End With
>
> With ActiveSheet.QueryTables.Add(Connection:= _
> "TEXT;" & strDir _
> , Destination:=Range("Q22"))
> .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 = False
> .TextFileSemicolonDelimiter = False
> .TextFileCommaDelimiter = True
> .TextFileSpaceDelimiter = False
> .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
> .TextFileTrailingMinusNumbers = True
> .Refresh BackgroundQuery:=False
> End With
> End Sub
>

 
Reply With Quote
 
=?Utf-8?B?TGVBbm4=?=
Guest
Posts: n/a
 
      4th Oct 2007
Good suggestion - I've been busy but I'll give a try soon and let you know.

Thanks

"Joel" wrote:

> I think the problem is based on the data you are trying to import. Not sure.
> Try go on spreadsheet to tools - Macro - Record Macro. Then manually import
> each of the two files. On spreadsheet Menu - Data - Import External Data -
> New web query. Enter in URL address the location of the two files. The URL
> can be a file on your disk. Just enter c:/temp/... . Use forward slashes
> instead of backward slashes. Then stop recording macro and compare the macro
> for importing the two files. You can actually run the macro again to make
> sure the recorded macro works properly.
>
> "LeAnn" wrote:
>
> > I have 2 procedures in a module. One imports external data (.csv) to a named
> > sheet (which works) then calls another procedure wthich imports a .dat file.
> > I'm getting the error above during the second import. I have checked using
> > debug.print and the file path is correct. The last line of code (.Refresh...)
> > is causing my problem. Here's my code. Any ideas?
> >
> > Thanks
> > LeAnn
> >
> > CODE:
> > Sub ImportData(strFile As String)
> > '
> >
> > Dim strDir As String
> > strDir = "my network path" & strFile
> >
> > With Worksheets("Result")
> > .Select
> > .Range("a1").Select
> > End With
> >
> > With ActiveSheet.QueryTables.Add(Connection:= _
> > "TEXT;" & strDir _
> > , Destination:=Range("Q22"))
> > .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 = False
> > .TextFileSemicolonDelimiter = False
> > .TextFileCommaDelimiter = True
> > .TextFileSpaceDelimiter = False
> > .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
> > .TextFileTrailingMinusNumbers = True
> > .Refresh BackgroundQuery:=False
> > End With
> > End Sub
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button on Form to refresh hyperlink data in table - error 1004 & 3 CAMoore Microsoft Access VBA Modules 1 24th Oct 2008 07:13 PM
VBA "1004" error when .Refresh BackgroundQuery:=False Dennis Microsoft Excel Programming 2 25th Jul 2007 02:30 PM
VBA Find produces 1004 error =?Utf-8?B?QW5keQ==?= Microsoft Excel Programming 3 26th Sep 2006 07:31 PM
runtime error 1004 saveas text file =?Utf-8?B?SmFuaXM=?= Microsoft Excel Programming 2 1st Sep 2006 11:11 PM
Excel 97 & VBA Runtime Error 1004 with Find Nickd Microsoft Excel Worksheet Functions 1 21st Jul 2004 11:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:13 PM.