+ Reply to Thread
Results 1 to 10 of 10

Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder Dir.

  1. #1
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder Dir.

    I have a table of contents file that has a button to update it with new files if the file is not already in the list (See related post Here). Now I am trying to update the list if the file name in the list is not found in the Folder/Sub Folder Directory by changing the fill color and the font color of the file that is no longer in the directory. The purpose of this is to allow users to know that a file was deleted, and if it was deleted by accident we can contact IT to retrieve it for us.

    I am not sure what I did wrong, but if you look at the sample file I have several files that get filled like they are not there and then it continues to add additional rows of formatting to the end of the list of files. I also cannot figure out why the specified range for filling is from A-E but what fills is B-F.

    In the sample file, the line item "Test - File.docx" was added to a folder, the list was updated with the Call SearchFolders Routine commented out. I then deleted the test file and cleared the commenting for the Call SearchFolders Routine. and then lots of files ended up getting updated with formatting when only the one test file should have changed.

    Here is the entire process. Everything worked as expected then I tried to add the SearchFolders routine to search for files based on the list.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    Hi, you will need an additional macro that loops thought all the cells in column B

    you have to use the hyperlink's address and check if the file is present in that address is present
    For example: Cell B3
    Please Login or Register  to view this content.
    In this case

    Please Login or Register  to view this content.
    Use myFullFileName as the variable to check if the file is present and then do your code accordingly like font and color

    Hope this helps
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    I also cannot figure out why the specified range for filling is from A-E but what fills is B-F.
    The range for filling is a relative range, relative to the range FileName :
    Please Login or Register  to view this content.
    FileName is column B, so columns A through E relative to column B is B through F. When range is used relative to other ranges, the child ranges are processed as if the first cell of the parent range object is cell A1 -This example code with display "$E$5" - if you don't understand why, then post back

    Please Login or Register  to view this content.
    If you want, you could change that range to be relative to the range FileName (this is the same)

    Please Login or Register  to view this content.
    Or just drop the FileName range object:
    Please Login or Register  to view this content.
    As to your code, you should just explain what you want to do - I think the easiest thing is to change the color of all the files to show that they are missing, then as you find files by searching the folders, find them in the list and change the color back to show them as available if they are found, otherwise add them to the bottom. Then you won't need to look for files based on the list - you will have identified those missing files based on the fact that they were not found at all.
    Last edited by Bernie Deitrick; 04-23-2019 at 03:15 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    Keebellah, I was able to use the Hyperlink as you suggested. Funny thing though is if I clear out the table and run it as if it were the first time it errors out but if the table has data in it and it is updated, it works fine. Luckily it wont ever be empty once I have it go live. I am curious to know why it does error out and after a lot of data has already been entered.

    Here is wat I ended up using for the SearchFolders macro
    Please Login or Register  to view this content.
    Bernie, thanks I did not notice the relative range reference. I dropped the FileName reference and it worked perfect.

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    The fact that it throws error when the table is empty is understandable, I didn't add an on error statement because that is something I thought you might think of your self. but glad it works and Bernie's notice was great
    Don't forget to mark the post SOLVED

  6. #6
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    Keebellah, I figured it out by adding the following to the SearchFolders routine. I figured out that the error was being thrown because when the table populates, it ends up leaving a blank row in the table that does not have a hyperlink.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    That's another way to do it. Good job

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    If you select a cell in column B and in the VBA editors immediate window you type type following you will see the correct path.
    So your code is missing something

    Please Login or Register  to view this content.
    The line is read is the result of the hyperlink's address

  9. #9
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    Keebellah - I figured out that even though the hyperlink address is correct in the cells and the files open when selected, VBA recognizes that the TOC file is in one of the folders in the hyperlink path and therefore sees it as a Relative path and not an absolute path. Stepping through the code and looing at the hyperlink address and seeing that it was starting with the Mechanical folder had me confused at first. But I came up with the following solution that seems to be working for now. I check to see if the hyperlink has the starting path dstcontrols.local, and if it does I continue, if it does not then I add the workbook path of the TOC to the variable that holds the hyperlink address.

    Please Login or Register  to view this content.

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder D

    Do keep in mind that Thisworkbook.Path only works IF that is the same path as dstcontrols.local

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy Files from One Folder to Another Folder based on a List In Excel
    By civram1982 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2019, 06:34 AM
  2. [SOLVED] Macro to list and open .xlsm files in folder and sub-folder
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-24-2019, 07:35 PM
  3. Replies: 18
    Last Post: 02-18-2019, 07:42 AM
  4. Create Folder & Check if Folder Exists if Not Create Folder & then Save File
    By Quivolt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-28-2017, 05:31 AM
  5. Having Trouble Checking Whether A Folder Exists Using VBA
    By pablowilks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-13-2016, 10:52 AM
  6. Create folder and move files to that folder based on file name
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2016, 06:58 PM
  7. Updating list of all files in a folder
    By Mark.jpl in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-29-2011, 11:26 AM

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