Results 1 to 3 of 3

Thread: How to rename a file in VB6

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2010
    Location
    Bristol
    Posts
    36

    How to rename a file in VB6

    Hi Folks, I'm sorry if this is a trivial question but here goes.
    I wish to rename a file (a workbook in this case) leaving it in the same folder.

    I am using: " name firstname.xls as newname.xls " after I have checked that firstname.xls exists. I get "File not found" failure.

    Because the Path is very long, I can't view it by hovering the cursor over the variable MyPath but I think it is within the 255 character length allowed. On occasion this method has worked without the path before the file name but I don't know why it won't work now! I wondered whether I should be using a variant for the file names instead of a string variable.

    I have also seen a "Rename" keyword suggested but if I type this into the help system it says keyword not recognised. Any help you can give me will be very much appreciated. Thanks in anticipation.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to rename a file in VB6

    Thread moved from the 'VB.Net' (VB2002 and later) forum to the 'VB6 and Earlier' forum


    Specifying the full path is important (for this and anything else), because if you don't specify it then you cannot predict which folder will be assumed - various things can change it, including several whilst your program is running.

    In terms of not seeing the whole variable value while hovering, add a Watch instead (if you don't know how, see the Debug Tutorial in our Classic VB FAQs), or print it to the immediate window (using: Debug.Print MyPath ).

    Using the Variant data type is very unlikely to make a difference, and it is generally best avoided if you can.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2010
    Location
    Bristol
    Posts
    36

    Re: How to rename a file in VB6

    Thank you Si, That was quick! I will have a go - I do know about adding a watch but the debug.print was new to me. I will return!

Posting Permissions

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



Click Here to Expand Forum to Full Width