Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Working with Flat files in Excel (2000)

    Hi

    I have a very simple question, I want to write a simple file in an Excel macro and I am always getting an error 53, is there something I need to do before I can use Open, Write, FileCopy etc.

    This is the code that I am using

    Sub file_handler()

    strFilePath = "c:"

    strText1 = strFilePath + "BlankLog.txt"
    strText2 = strFilePath + "Log_" + Str(Date) + Str(Time)

    FileCopy strText1, strText2

    Open strFilePath + "Log_" + Str(Date) + Str(Time) + ".txt" For Output As #1

    End Sub

    Have I missed something!!!!!!!!!!!!

    Regards

    Mike

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Working with Flat files in Excel (2000)

    strText2 = strFilePath + "Log_" + Str(Date) + Str(Time)
    is NOT a valid file name. "/" and ":" are not allowed

    Try this: or a variant in the naming of strtext2
    <pre>Sub file_handler()
    strFilePath = "c:"
    strText1 = strFilePath + "BlankLog.txt"
    strtext2 = strFilePath + "Log_" + Format(Now(), "mmddyy hh-mm am/pm")
    FileCopy strText1, strtext2
    Open strtext2 For Output As #1
    End Sub
    </pre>

    Steve

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Working with Flat files in Excel (2000)

    Thanks Steve,

    I was being really stupid......................................

    Works fine

    Regards

    Mike

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Working with Flat files in Excel (2000)

    Apart from the wrong characters, note that it is theoretically possible that the Time has changed between the codelines and that the Open statement tries to open a different file (If I'm not mistaken, XL will create the file if it is not there). Better is to use the string variable StrText2 in both the renaming and the open statement.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

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