+ Reply to Thread
Results 1 to 2 of 2

File Name Causes Runtime Error 1004

Hybrid View

  1. #1
    Robert
    Guest

    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. #2
    Norman Jones
    Guest

    Re: 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" <Robert@discussions.microsoft.com> wrote in message
    news:502BE337-03F4-4F9C-8D42-108652DF37D7@microsoft.com...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1