Consulting

Page 6 of 7 FirstFirst ... 4 5 6 7 LastLast
Results 101 to 120 of 125

Thread: Combine recursive listing with excluded code

  1. #101
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Open the Immediate Window and enter

    ?p.Name+Enter

    The fact that it works on my PC and not on yours makes me wonder if there's something about the data
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  2. #102
    Well what I did was change the drive letter of D into C to suit my computer path that's it. Also, why is there a list in column I, K and M...looking at the code the exclude list was in column C, D and E.

    ?p.Name+Enter
    returns an error run time error 424: object required. It doesn't work for any parent folder regardless where it's located even other parent folders with shorter folder paths
    Last edited by anmac1789; 05-20-2021 at 07:21 PM.

  3. #103
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    what I did was change the drive letter of D into C to suit my computer path
    I recall that some user folders can't be in the root of C:




    Also, why is there a list in column I, K and M...looking at the code the exclude list was in column C, D and E.
    I just moved them out of the way
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #104
    I recall that some user folders can't be in the root of C:
    The problem is that it doesn't work for any folder even within the Downloads folder

  5. #105
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Can you attach the failing workbook?

    Are you using the same 'very long folder path.zip' from post 91?

    I used

    \\?\c:\Users\Daddy\Downloads\very long folder path

    without problems
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #106
    I am getting the same error message again. I downloaded the exact same workbook that you have attached in the previous post.

    Are you using the same 'very long folder path.zip' from post 91?
    I am also using the same zip file and testing it out on that and also on smaller folders on my computer and still i am getting the same runtime error 5 msg

    run time error.PNG
    highlight.jpg
    Attached Images Attached Images
    Last edited by anmac1789; 05-21-2021 at 02:22 PM.

  7. #107
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    1. For now, remove the UCase( ) around p.path and see if the error goes away


    2. Try this also

    https://newtonexcelbach.com/2014/03/...-lcase-in-vba/

    So mosey on over to Tools > References, and look for any library prefixed with “MISSING”.

    That’s the real culprit.


    If this doesn’t fix the problem, then close Excel, clean out the temp directory, clean out %appdata%\Roaming\Microsoft\Forms, then restart Excel. If that doesn’t help you probably need to repair/reinstall Office.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #108
    1. For now, remove the UCase( ) around p.path and see if the error goes away
    I've removed that from isFolderExcluded sub, isFileExcluded sub and isSpecificFileExcluded sub. Still getting the same error

  9. #109
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Well ...

    put the UCase (..) back and try the second suggestions

    If that doesn't work, then I'm really out of ideas since it works here.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  10. #110
    I've tried pre-fixing vba before Ucase and it still doesn't work just like the website suggests.. so im guessing im going to re-install office. Because I was hit with a bad virus yesterday and I was scanning for 6 hrs and it turned up like 105 trojans and alot of files were affected in the temp folder. So im going to try that now.

  11. #111
    So i re-installed excel 365 and tried to run Excludes_20.xlsm again but still I am getting run time error 5. I was looking on this website: https://www.mrexcel.com/board/thread...gument.825523/

    it says
    the worksheet function Match requires a range object as the second argument, not an array
    Could this have anything to do with it ?

  12. #112
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Sub M_snb()
       sn = Split("That is not correct")
       MsgBox Application.Match("not", sn, 0)
    End Sub
    Sub M_snb()
      MsgBox Application.Match("not", Split("this is not correct"), 0)
    End Sub

  13. #113
    Sub M_snb()
    sn = Split("That is not correct")
    MsgBox Application.Match("not", sn, 0)
    End Sub
    By itself, doesn't work because I have Option Explicit. But if I add Dim sn As Variant then the sub works. The second one also works without having to define split with dim

  14. #114
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by anmac1789 View Post
    So i re-installed excel 365 and tried to run Excludes_20.xlsm again but still I am getting run time error 5. I was looking on this website: https://www.mrexcel.com/board/thread...gument.825523/

    it says Could this have anything to do with it ?

    Doubt it

    Match works with arrays and it files an excluded folder

    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  15. #115
    which directory path are you testing this on ? I have done ?isarray(aryFoldersToExclude) and it returns false the error message. I also tested aryFoldersToExclude in the watch window and the value returned "out of context" and type - "empty".

    So I've tested this on another computer and it seems to work. It seems that even after re-installing excel the code on my laptop doesn't work. What is going on here....

    Also, it seems that in the sub isSpecificFileExcluded and isFolderExcluded the arguement inside UCase() should be changed to p.Path not p.name because paths are not being excluded properly, they were only excluding subfolder name and filename

    here is the problem workbook so you can see for yourself if there are any changes compared to your workbook
    Attached Files Attached Files
    Last edited by anmac1789; 05-23-2021 at 09:05 PM.

  16. #116
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    The way it (is intended) to work is below

    It does seem to do what it's supposed to

    1. If isFolderExcluded(oPath) returns True, then the recursion down that folder path stops

    2. If isFileExcluded(oFile) or isSpecificFileExcluded(oFile) return True, then the file is not added


    
    Sub getFiles(oPath As Object)
        Dim oFolder As Object, oSubFolder As Object, oFile As Object
    
    
        If isFolderExcluded(oPath) Then Exit Sub  '   stops recursion
            
        Call addFileFolder(oPath)
        
        For Each oFile In oPath.Files
            If Not isFileExcluded(oFile) Then
                If Not isSpecificFileExcluded(oFile) Then Call addFileFolder(oFile)
            
            Else
                If Not isSpecificFileExcluded(oFile) Then Call addFileFolder(oFile)
            End If
        Next
        
        For Each oSubFolder In oPath.SubFolders
            Call getFiles(oSubFolder)
        Next
    End Sub

    The way you described what you wanted to do, the 2 'File' excludes were based on the file .Name so I think that it's correct

    because paths are not being excluded properly, they were only excluding subfolder name and filename
    I was excluding folders from 'hell yeah' and below (ver 20a)
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  17. #117
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by anmac1789 View Post
    which directory path are you testing this on ? I have done ?isarray(aryFoldersToExclude) and it returns false the error message. I also tested aryFoldersToExclude in the watch window and the value returned "out of context" and type - "empty".

    So I've tested this on another computer and it seems to work. It seems that even after re-installing excel the code on my laptop doesn't work. What is going on here....

    Also, it seems that in the sub isSpecificFileExcluded and isFolderExcluded the arguement inside UCase() should be changed to p.Path not p.name because paths are not being excluded properly, they were only excluding subfolder name and filename

    here is the problem workbook so you can see for yourself if there are any changes compared to your workbook

    Correcting / changing the two marked lines and entering

    A1 = \\?\c:\users\daddy\downloads\very long folder path
    C1 = hell yeah

    seems to work


    Private Function isFolderExcluded(p As Object) As Boolean
        Dim i As Long
        
        i = -1
        On Error Resume Next
        i = Application.WorksheetFunction.Match(UCase(p.Name), aryFoldersToExclude, 0)  '   <<<<<<<<<<<<<<<<<<<<<<<<<
        On Error GoTo 0
    
    
        isFolderExcluded = (i <> -1)
    End Function
    
    
    Private Function isFileExcluded(p As Object) As Boolean
        Dim i As Long
        
        i = -1
        On Error Resume Next
        i = Application.WorksheetFunction.Match(UCase(p.Name), aryFilenamesToExclude, 0)
        On Error GoTo 0
    
    
        isFileExcluded = (i <> -1)
    
    
    End Function
    
    
    Private Function isSpecificFileExcluded(p As Object) As Boolean
        Dim i As Long
        
        i = -1
        On Error Resume Next
        i = Application.WorksheetFunction.Match(UCase(p.Name), arySpecificFilesToExclude, 0)    '   <<<<<<<<<<<<<<<<<<<<<<
        On Error GoTo 0
    
    
        isSpecificFileExcluded = (i <> -1)
    
    
    End Function
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  18. #118
    I dont know why the above code was re-written I did not see any change. It is the same exact code in Excludes_20a and I also did a test just to list a parent folder and all it's files without any excludes, I am still getting run-time error 5: invalid procedure call or argument on

    i = Application.WorksheetFunction.Match(UCase(p.Name), aryFoldersToExclude, 0)

  19. #119
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Again, it works for me

    One thing to check ...

    In the VBE go to Tools, Options, and make sure "Unhandled Errors" is selected


    Capture.JPG

    Also I added a check to fail softly if there was no top level folder specified

    In your 20 (Problem file) it was blank and generated an ugly error
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  20. #120
    In the VBE go to Tools, Options, and make sure "Unhandled Errors" is selected
    Ok so, it seems like now it searches. What does "break on unhandled errors" mean? does it mean that it's ignoring run time error 5 and just forcing itself to proceed to complete the code?

Posting Permissions

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