Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default File Name Causes Runtime Error 1004

Using Excel 2003, an application asks the user for a .txt file to open using
the open dialog. After the file has been opened, the code changes the name of
the sheet using Sheets(1).Name = "Data".

This works fine most of the tiime but with some file names, it causes
Runtime Error 1004. An example of a name that causes the error is
"report_PO_11-3-2005_11_3_2005[1].txt". If I rename the file and take out the
brackets, it works OK.

Is there some way I can avoid this error so that the user doesn't have to
rename the file every time? These files are downloaded from a web site so I
don't have anty control over the names.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default File Name Causes Runtime Error 1004

Hi Robert,

Try something like:

Dim sStr As String

sStr = "report_PO_11-3-2005_11_3_2005[1]"

sStr = Replace(sStr, "[", "")
sStr = Replace(sStr, "]", "")

Sheets(1).Name = sStr

---
Regards,
Norman


"Robert" wrote in message
...
Using Excel 2003, an application asks the user for a .txt file to open
using
the open dialog. After the file has been opened, the code changes the name
of
the sheet using Sheets(1).Name = "Data".

This works fine most of the tiime but with some file names, it causes
Runtime Error 1004. An example of a name that causes the error is
"report_PO_11-3-2005_11_3_2005[1].txt". If I rename the file and take out
the
brackets, it works OK.

Is there some way I can avoid this error so that the user doesn't have to
rename the file every time? These files are downloaded from a web site so
I
don't have anty control over the names.



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
Runtime Error 1004??? kewlrunnings Excel Programming 5 October 25th 05 07:34 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Runtime error 1004 Ajit Excel Programming 2 January 13th 05 02:55 PM
Runtime error '1004': Capinvest Excel Programming 2 August 4th 03 07:16 PM
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 08:59 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"