Aug 21 2022 01:21 PM
when we get any additional file name in same pathname,why we call Dir again with no arguments
Aug 21 2022 01:30 PM
SolutionYou must always call Dir first with arguments. This will return the name of the first file (or folder) that matches the specification.
Each time you call Dir without arguments after that, it will return the name of the next file (or folder) that matches the original specification.
So you can use code like this:
Const sFolder = "C:\Excel\"
Dim sFile As String
' Get the name of the first Excel workbook in the folder
sFile = Dir(sFolder & "*.xlsx")
' Loop through the workbooks until none is found
Do While sFile <> ""
' Do something with the file name
MsgBox "Found file: " & sFile
' Get the next file name
sFile = Dir
Loop
Aug 21 2022 01:30 PM
SolutionYou must always call Dir first with arguments. This will return the name of the first file (or folder) that matches the specification.
Each time you call Dir without arguments after that, it will return the name of the next file (or folder) that matches the original specification.
So you can use code like this:
Const sFolder = "C:\Excel\"
Dim sFile As String
' Get the name of the first Excel workbook in the folder
sFile = Dir(sFolder & "*.xlsx")
' Loop through the workbooks until none is found
Do While sFile <> ""
' Do something with the file name
MsgBox "Found file: " & sFile
' Get the next file name
sFile = Dir
Loop