PDA

View Full Version : Macro listing files in folder, used to list all now only first



Johan90
05-07-2018, 08:35 AM
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

p45cal
05-08-2018, 12:41 AM
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).

Johan90
05-08-2018, 01:45 AM
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.

p45cal
05-08-2018, 01:58 AM
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?