+ Reply to Thread
Results 1 to 7 of 7

Macro to Locate and Delete File saved from cell variable

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    Jackson, MI
    MS-Off Ver
    Excel 2010
    Posts
    8

    Macro to Locate and Delete File saved from cell variable

    Long Story Short - or atleast as best I can !

    A macro creates a Workbook and saves it as WORK ORDER X, PART X, PRODUCTION.xlsm on a Shared Drive. The Work Order and Part# will always be variables as the same Master Workbook is used for several different models.

    Example: In the Summary Folder, I may have the following files:
    WORK ORDER 12345, PART MM176, PRODUCTION.xlsm
    WORK ORDER 45678, PART MM123, PRODUCTION.xlsm

    At the end of the Work Order, the users presses a button to resave file as WORK ORDER X, PART X, REWORK.xlsm to alert the shift leader that production is complete and reworks can be started.

    The only problem is this leaves the original PRODUCTION.xlsm file in the folder still and creates confusion. I need the PRODUCTION.xlsm to be deleted when the .REWORK.xlsm is created and I end up with:
    WORK ORDER 12345, PART MM176, PRODUCTION.xlsm
    WORK ORDER 45678, PART MM123, PRODUCTION.xlsm
    WORK ORDER 45678, PART MM123, REWORK.xlsm

    I want to delete the old PRODUCTION.xlsm through a macro which can be stored in the PRODUCTION Workbook so the Shift Leader does not have to go in and remove the old .PRODUCTION.xlsm file. I do not want to move it to a different folder for 2 reasons - 1) I want the Shift Leader to be able to go in to one folder and find everything he needs - Both the .PRODUCTION and REWORK files (computer illeterate but getting better), 2) I do not want duplicate files created.

    Maybe I am looking at this from the wrong angle, it should be simple but.....the fact that it saves based on a variable has me spun! Have attached code below. Please tell me this is easier than I making it out to be!

    HTML Code: 

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Macro to Locate and Delete File saved from cell variable

    You will have to work with your existing code structure to make this work (set the variables, test if the file exists, error check, etc), but a quick example is below. This code posted deletes a file named TestFileAddIns.xlsx which is saved on my Desktop.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-18-2012
    Location
    Jackson, MI
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to Locate and Delete File saved from cell variable

    The issue is created becuase I am using a variable - it will never have the same name. The original form is a template that can not be over writtien. The same template will produce different files, it will not always save as "TestFileAddins.xlsx". Using your example above, it would be named as TestFileAddins PARTXXXX.xlsx - The PARTXXX will always be a variable.

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Macro to Locate and Delete File saved from cell variable

    I understand that, which is why I suggested that you adapt the code to meet your specific requirements. For example, instead of hard coding fName, you can create a string to reference the specific file based on your variables. How would the file programmatically know which file to delete? As an example, let's say that the part name is stored in cell A1. The code would look more like:

    Please Login or Register  to view this content.
    Does this help?

  5. #5
    Registered User
    Join Date
    10-18-2012
    Location
    Jackson, MI
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to Locate and Delete File saved from cell variable

    going to give it a try tonight and let you know. I think the part you just added was what I couldn't wrap my head around. I tried it a few different ways but still couldn't get it! Thanks.

  6. #6
    Registered User
    Join Date
    10-18-2012
    Location
    Jackson, MI
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to Locate and Delete File saved from cell variable

    Works like a charm! Brilliant!

  7. #7
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Macro to Locate and Delete File saved from cell variable

    Glad we got it to work.

+ 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