+ Reply to Thread
Results 1 to 10 of 10

Vba to rename file then move old file

  1. #1
    Registered User
    Join Date
    03-04-2011
    Location
    Enfield CT.
    MS-Off Ver
    Excel 2003
    Posts
    6

    Vba to rename file then move old file

    Hi, need help on a VBA that Ian working on. What I want it to do is when a cell value changes save the file under a new name then move the old file to another folder. So far I have been able to do the file save portion but when I start adding the move portion it hangs up. Also I don't want the template file to be moved. Only files saved from the template going forward. Any help would be appreciated.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Vba to rename file then move old file

    Hi, scoth,

    Only files saved from the template going forward.
    Has the original file being saved as a template (*.xlt) or is it a normal workbook?

    You could save the name of ActiveWorkbook.Name or ActiveWorkbook.FullName in a variable (here: BookName), use SaveAs for the getting the new file and then use
    Please Login or Register  to view this content.
    to move the workbook (at least in the same drive).

    HTH,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Vba to rename file then move old file

    Can you post your code? That would provide the details that your description does not e.g. path, file naming conventions. Include comments and pseudo-code where you are having difficulties.

    Take note to surround the code with code tags (see my signature block below).
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    03-04-2011
    Location
    Enfield CT.
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Vba to rename file then move old file

    Template file is a regular Excel file. Idea is that associate will use template to start a part number specific file. Once create the part number specific file will be used, when ever the file Revision is changed (cell E7) a new file is to be saved with a file with the new revision at end of file name, then move the old part number file to an obsolete folder. Code has provisions to create this obsolete folder if the obsolete folder does not exist. Below is the code I have so far, code worked fine until I added the portion to create obsolete folder and move old file. Don't laugh to hard, I am new at this VBA coding, , Thanks again for your help.

    Please Login or Register  to view this content.
    Last edited by scoth; 07-07-2013 at 12:36 PM. Reason: fix code tags

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Vba to rename file then move old file

    The code isn't that bad. Nice fix with the code tags.

    Can I ask why you prompt the user for a file name? Isn't the file name determined by cell values? Are you meaning to prompt the user for a destination folder?

    What is the file name of the template file before it is saved as something else?

    Can you give some examples of the file names and the naming convention you are using? What is in cell E7; numbers, text?

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Vba to rename file then move old file

    Hi, scoth,

    everythin gyou have so far letīs the workbook opened from the basic folder back in place as you canīt move an open workbook with Name (AFAIK only copy it) which would lead you to a twistthe opened workbook is still active in the folder from which is was opened.

    I had to disable process (whatever that may be) in order to test the code:
    Please Login or Register  to view this content.
    This code will check if the name of the given directory is part of the FullName of the workbook and should act accordingly.

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    03-04-2011
    Location
    Enfield CT.
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Vba to rename file then move old file

    The prompt is so they can move the file to its correct location, the template file is stored in one location where as the part number files are stored by part number/operation number. The code auto populates the name in the save as popup, they just need to verify the location is correct.

    There is 2 templates, depending on machine type (this is aerospace manufacturing documents) template name is _lathe_rev_tool_set-up shts_7-2-2013, the other is the same except first name is Mill

    Saved files for part number file would be part number_op number_program rev. program rev populated by cell E7 and is text.

    To you see anything that stands out as to why it hangs up, also any cell change triggers it, not just when E7 is changed.

  8. #8
    Registered User
    Join Date
    03-04-2011
    Location
    Enfield CT.
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Vba to rename file then move old file

    Process was an attempt to run a sub process to get the file move to work, thought I had removed before posting.

  9. #9
    Registered User
    Join Date
    03-04-2011
    Location
    Enfield CT.
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Vba to rename file then move old file

    Holger,
    Thanks for the code, I tried and found it to be close to what I was looking for. What it is doing is saving the new file in the obsolete folder and the reqular folder. What is intended would be to have the old file move to the obsolete and only have the new file in the reqular folder.

  10. #10
    Registered User
    Join Date
    03-04-2011
    Location
    Enfield CT.
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Vba to rename file then move old file

    Got it to work. Thanks to all who offered their advise

    HTML Code: 

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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