NessPJ
Active Member
- Joined
- May 10, 2011
- Messages
- 422
- Office Version
- 365
Hey guys,
I would like to create a simple tool in Excel that can list a few files in the specified folder together with the modified date in Excel.
Now i have 2 pieces of code that should do this, but i noticed that their approach seems different.
The first one will not work for me (it gives me a 'user defined type not defined' error), the second one works but does not scan the entire folder...it gets the modified date from a specified filename only.
This routine gives a user defined type not defined error on oFSO:
This routine only goes to a specific file:
I have a feeling the second routine works because it 'creates' the FileSystemObject as to where the first one only refers to it or something......
I would like to create a simple tool in Excel that can list a few files in the specified folder together with the modified date in Excel.
Now i have 2 pieces of code that should do this, but i noticed that their approach seems different.
The first one will not work for me (it gives me a 'user defined type not defined' error), the second one works but does not scan the entire folder...it gets the modified date from a specified filename only.
This routine gives a user defined type not defined error on oFSO:
Code:
Private Sub Checkfiles()
Dim TargetSheet As String
Dim TargetCell As String
Dim Zoekpad As String
TargetSheet = Sheets("Parameters").Range("C6").Value
TargetCell = Sheets("Parameters").Range("C8").Value
Zoekpad = Sheets("Parameters").Range("C4").Value
Call ListFilesFSO(Zoekpad)
End Sub
Public Sub ListFilesFSO(ByVal sPath As String)
Dim oFSO As FileSystemObject
Dim oFolder As Folder
Dim oFile As File
Set oFSO = New FileSystemObject
Set oFolder = oFSO.GetFolder(sPath)
For Each oFile In oFolder.Files
'Debug.Print oFile.Name
Sheets(TargetSheet).Range(TargetCell).Value = oFile.Name
Next 'oFile
Set oFile = Nothing
Set oFolder = Nothing
Set oFSO = Nothing
End Sub
This routine only goes to a specific file:
Code:
Sub getdate()
Dim fileModDate As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("\\192.168.1.4\test\testfile.txt")
fileModDate = f.DateLastModified
Sheets("Sheet1").Range("b2").Value = fileModDate
End Sub
I have a feeling the second routine works because it 'creates' the FileSystemObject as to where the first one only refers to it or something......
Last edited: