Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel 2007 Import .txt file error 1004

I am using Excel 2007 to import a text delimited file with the path of the
file as part of the macro-recorded process.

The name of the file (example): is 123_0201_0228.txt

Since the date portion of the name changes, I changed the macro to look for
path\123*.txt

When I go to run it again, I get the following info box:

Run-time error '1004':
Microsoft Office Excel cannot access the "path\123*.txt". There are several
possible reasons.

1. The file name or path does not exist.
2. The file is being used by another program.
3. The workbook you are trying to save has the same name as a. . . (I don't
know how this sentence ends).

The portion that fails is as follows:

Cells.Select
Selection.ClearContents
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;K:\path\123*.txt" _
, Destination:=Range("$A$1"))
..Name = "123*"
- truncated to fit window -
..Refresh BackgroundQuery:=False
End With
Cells.Select
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel 2007 Import .txt file error 1004

Just to clarify, where I am using the word "path" in my string - that is not
the actual string - but I am obligated to hide company directory information.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Excel 2007 Import .txt file error 1004

You have to give an exact name in "TEXT;K:\path\123*.txt"

You might build a string with the right name using DATE etc. but you need to
pass an exact name

"Woodstock" wrote:

I am using Excel 2007 to import a text delimited file with the path of the
file as part of the macro-recorded process.

The name of the file (example): is 123_0201_0228.txt

Since the date portion of the name changes, I changed the macro to look for
path\123*.txt

When I go to run it again, I get the following info box:

Run-time error '1004':
Microsoft Office Excel cannot access the "path\123*.txt". There are several
possible reasons.

1. The file name or path does not exist.
2. The file is being used by another program.
3. The workbook you are trying to save has the same name as a. . . (I don't
know how this sentence ends).

The portion that fails is as follows:

Cells.Select
Selection.ClearContents
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;K:\path\123*.txt" _
, Destination:=Range("$A$1"))
.Name = "123*"
- truncated to fit window -
.Refresh BackgroundQuery:=False
End With
Cells.Select

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel 2007 Import .txt file error 1004

Well, I did change the name of my text file to simply 123.txt and had the
exact path in the macro, and got the same error.

The macro runs as soon as I open my Spreadsheet - could it be that it is a
sharing violation to a read-only SS?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Excel 2007 Import .txt file error 1004

Did you update the .name line also?

I tested with the following and could import the file without any problem
Sub t()
Cells.Select
Selection.ClearContents
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\Sheeoo\Desktop\Book2.txt" _
, Destination:=Range("$A$1"))
..Name = "Book2.txt*"
..Refresh BackgroundQuery:=False
End With
Cells.Select
End Sub


"Woodstock" wrote:

Well, I did change the name of my text file to simply 123.txt and had the
exact path in the macro, and got the same error.

The macro runs as soon as I open my Spreadsheet - could it be that it is a
sharing violation to a read-only SS?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel 2007 Import .txt file error 1004

That worked!

thank you so much for your 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
Import an MS Money 2007 file into MS Excel 2007 worksheet DonF Excel Discussion (Misc queries) 0 August 29th 08 11:14 PM
Run-time error 1004 since upgrading from Excel 2003 to 2007. PJ Excel Programming 1 July 23rd 08 11:55 PM
Excel 2007 VBA - Run-time error 1004 SG Excel Programming 10 January 28th 08 03:48 PM
Error Code 1004 when exporting from VB app to Excel 2007 sue mac Excel Discussion (Misc queries) 0 September 11th 07 08:10 AM
runtime error 1004 when opening excel file via VBA in a browser Ken Hunter Excel Programming 2 July 31st 03 03:33 PM


All times are GMT +1. The time now is 02:26 PM.

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

About Us

"It's about Microsoft Excel"