Hello everyone.
Trying to pass a string valut from a function to a routine but i don't understand why not my value is not accepted by the procedure
Remark that the line of code 'ListFilesInFolder "G:\Doc" work perfectly but why not my value from the function?
Thanks for ure advises
Trying to pass a string valut from a function to a routine but i don't understand why not my value is not accepted by the procedure
Code:
Public Function UsrInput() As String
UserInput = InputBox("Path:")
End Function
Sub TestListFilesInFolder()
Workbooks.Add ' create a new workbook for the file list
' add headers
With Range("A1")
.Formula = "Folder contents:"
.Font.Bold = True
.Font.Size = 12
End With
Range("A3").Formula = "File Name:"
Range("B3").Formula = "File Size:"
Range("C3").Formula = "File Type:"
Range("D3").Formula = "Date Created:"
Range("F3").Formula = "Date Last Modified:"
Range("A3:H3").Font.Bold = True
ListFilesInFolder UsrInput()
'ListFilesInFolder "G:\Doc"
End Sub
Sub ListFilesInFolder(SourceFolderName As String)
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Set FSO = New Scripting.FileSystemObject
If FSO.FolderExists(SourceFolderName) Then
Set SourceFolder = FSO.GetFolder(SourceFolderName)
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
' display file properties
Cells(r, 1).Formula = FileItem.Name
Cells(r, 2).Formula = FileItem.Size
Cells(r, 3).Formula = FileItem.Type
Cells(r, 4).Formula = FileItem.DateCreated
Cells(r, 6).Formula = FileItem.DateLastModified
r = r + 1 ' next row number
Next FileItem
Columns("A:H").AutoFit
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub
Remark that the line of code 'ListFilesInFolder "G:\Doc" work perfectly but why not my value from the function?
Thanks for ure advises