Consulting

Results 1 to 4 of 4

Thread: Macro listing files in folder, used to list all now only first

  1. #1
    VBAX Regular
    Joined
    May 2018
    Posts
    14
    Location

    Macro listing files in folder, used to list all now only first

    So I have this macro that was working as it should but now it only list the first file. It adds the full path if I press yes on the message box as it should.

    Anybody have any ideas?


    Sub ListFilesinFolder()
    
    Application.ScreenUpdating = False
    
    
    
    
    Dim Value As String
    Dim strt As Range
    
    
    
    
    Set strt = Range("A10")
    Value = Dir(Range("A5"), &H1F)
    
    
    Do Until Value = ""
    If Value <> "." And Value <> ".." Then
        strt = Value
        Set strt = strt.Offset(1, 0)
        End If
    
    
    Value = Dir
    
    
    Loop
    
    
    
    
    
    
    
    
    Range("A10").Select
    
    
    MSBX1 = MsgBox("List full path to files incl file name (Ja). List only file name (Nej).", vbYesNo)
    
    
    If MSBX1 = 6 Then
        Dim dir2 As String
        dir2 = Range("A5")
        
        Do Until ActiveCell.Value = ""
    
    
        ActiveCell.Value = dir2 & ActiveCell.Value
    
    
        ActiveCell.Offset(1, 0).Range("A1").Select
        Loop
         
         
    End If
    
    
    
    
    Range("A10").Select
    
    
    Application.ScreenUpdating = True
    
    
    End Sub

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    1. Can you confirm exactly what's in cell A5?
    2. The &H1F in the line Value = Dir(Range("A5"), &H1F) specifies that as well as files with no attributes, the files with the following attributes will be returned:
    vbReadOnly, vbHidden, VbSystem, vbVolume, vbDirectory
    Perhaps there's only one such file. Is that what you want?
    See if changing that line to:
    Value = Dir(Range("A5"))
    helps (I doubt it because &H1F is more inclusive than leaving that argument out altogether).
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    May 2018
    Posts
    14
    Location
    Quote Originally Posted by p45cal View Post
    1. Can you confirm exactly what's in cell A5?
    2. The &H1F in the line Value = Dir(Range("A5"), &H1F) specifies that as well as files with no attributes, the files with the following attributes will be returned:
    vbReadOnly, vbHidden, VbSystem, vbVolume, vbDirectory
    Perhaps there's only one such file. Is that what you want?
    See if changing that line to:
    Value = Dir(Range("A5"))
    helps (I doubt it because &H1F is more inclusive than leaving that argument out altogether).

    No I want all files in the directory, which it listed before from A10 and down but now it just return the first one.

    A5 refers to a concat function on the desired path without the ending \ that this concat funtion adds on the end. I tried it without and it dosent help. Confounded as to why it dosent work anymore, I havent altered anything in that area of the sheet and didnt touch the code.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Well, I can't see herre what might be going wrong (it works here). Therer are so many possibilities that it becomes nothing more than guesswork to try and solve.

    A TeamViewer session?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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