Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

Bestandsnamen zoeken in directory

Pagina: 1
Acties:

  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
Ik heb een Excel bestand Met allemaal bestandnamen.
Dit zijn word documentjes in het engels. Deze zelfde documentjes zijn er in nog 5 talen met allemaal dezelfde bestandsnaam alleen in een andere map en met 2 letters verschil IPV GB staat er bijv. DE of NL of FR enz.
nu wil ik graag een command button maken.
Zodra erop geklikt word, moet het volgende gedaan worden.

-de bestandsnaam die in kolom A staat, zoeken in een bepaalde directory naar een gelijksoortige bestandsnaam.
Met alleen de taal dus NL of DE of FR in de bestandsnaam als verschil
-Als deze gevonden is de naam van dit bestand plus wijzigingsdatum in Kolom C & D zetten.

Samengevat:

A3 = bestandGB.doc
Zoek in C:\Documenten naar document bestand*.doc
Als * =NL dan bestandsnaam in kolom C3 en Wijzigingsnaam in D3
Als * =DE dan bestandsnaam in kolom E3 en wijzigingsnaam in F3

enz...

Is dit mogelijk of niet? Ik heb er even op gezocht, maar kon alleen vinden dat je de bestandsnamen vanuit een
txt bestandje in excel moet importeren. :?

  • F_J_K
  • Registratie: Juni 2001
  • Niet online

F_J_K

Moderator CSA/PB

Front verplichte underscores

Dat is geen enkel probleem in VBA. O.a. [google=vba list filenames] geeft verschillende codevoorbeelden, dan hoef je alleen maar de filenames in te lezen en even het juiste filter er overheen te gooien.

'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind' (Terry Pratchett, Eric)


  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
Thanks F_J_K!

Ik ben er even mee gezocht en bijna direct een goede hit!
Ik krijg al een mooi lijstje met alle bestands namen.
Nu moet ik nog het stukje gaan schrijven waar ik wil zoeken naar documenten met een gelijke naam.

Maar dit moet wel lukken denk ik zo.
Mocht je daar een goed voorbeel van hebben toevallig zou het wel handig zijn :)

  • F_J_K
  • Registratie: Juni 2001
  • Niet online

F_J_K

Moderator CSA/PB

Front verplichte underscores

Nope :P

Maar met een combi van FOR, LIKE en en/of LEFT moet je er wel komen. En zo niet denkt men hier vast graag mee :)

(Geef als je klaar ben het resultaat ook even, dan kunnen anderen er van leren).

'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind' (Terry Pratchett, Eric)


  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
F_J_K schreef op woensdag 01 oktober 2008 @ 14:31:
Geef als je klaar ben het resultaat ook even, dan kunnen anderen er van leren.
Dit zal ik doen!
En oké dan ga ik even kijken, ik had zelf ook al een idee met LEFT en dergerlijke ja :)

Zodra ik er uit kom (of niet) dan zal ik het even posten.

  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
Dit is de code tot nu toe. Ik kan vanuit excel browsen voor een Folder, en alles wat hierin zit incl. subfolders, daar komen de benamingen van in een nieuw excel sheet met headings. De bedoeling is wel dat er een knop word aangemaakt met daaronder

Visual Basic:
1
2
3
Private Sub Commandbutton_Click()
PopulateDirectoryList 'willekeurige naam
End Sub


Daarna is het de bedoeling dat je onderstaande code in een module plakt.
wel moet je zorgen dat de sub naam gelijk is aan de naam die je in de code hierboven invoegd.
In mijn geval heb ik het "PopulateDirectoryList" genoemd.

Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Sub PopulateDirectoryList()
'dimension variables
Dim objFSO As FileSystemObject, objFolder As Folder
Dim objFile As File, strSourceFolder As String, x As Long, i As Long
Dim wbNew As Workbook, wsNew As Worksheet

ToggleStuff False 'turn of screenupdating

Set objFSO = New FileSystemObject  'set a new object in memory
strSourceFolder = BrowseForFolder 'call up the browse for folder routine
If strSourceFolder = "" Then Exit Sub

Workbooks.Add 'create a new workbook

Set wbNew = ActiveWorkbook
Set wsNew = wbNew.Sheets(1) 'set the worksheet
wsNew.Activate
'format a header
With wsNew.Range("A1:N1")
    .Value = Array("GB", "Modified Date GB", "DE", "Modified Date DE", "ES", "Modified Date ES", "FR", _
                   "Modified Date FR", "NL", "Modified Date NL", "PT", "Modified Date PT", "RU", "Modified Date RU")
    .Interior.ColorIndex = 15
    .Font.Bold = True
    .Font.Size = 10
End With

With Application.FileSearch
    .LookIn = strSourceFolder  'look in the folder browsed to
    .FileType = msoFileTypeAllFiles 'get all files
    .SearchSubFolders = True  'search sub directories
    .Execute  'run the search
           
    For x = 1 To .FoundFiles.Count 'for each file found, by the count (or index)
       i = x 'make the variable i = x
       If x > 60000 Then  'if there happens to be more than multipls of 60,000 files, then add a new sheet
          i = x - 60000  'set i to the right number for row placement below
          Set wsNew = wbNew.Sheets.Add(after:=Sheets(wsNew.Index))
          With wsNew.Range("A1:B1")
            .Value = Array("File", "Modified Date")
            .Interior.ColorIndex = 15
            .Font.Bold = True
            .Font.Size = 10
           End With

       End If
        On Error GoTo Skip 'in the event of a permissions error
          
        Set objFile = objFSO.GetFile(.FoundFiles(x)) 'set the object to get it's properties
         With wsNew.Cells(1, 1) 'populate the next row with the variable data
             .Offset(i, 0) = objFile.Name
             .Offset(i, 1) = objFile.DateLastModified

             
         End With
          ' Next objFile
Skip:
'this is in case a Permission denied error comes up or an unforeseen error
'Do nothing, just go to next file
     Next x
     
     
wsNew.Columns("A:N").AutoFit

End With

'clear the variables
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
Set wsNew = Nothing
Set wbNew = Nothing
       
ToggleStuff True 'turn events back on
End Sub

Sub ToggleStuff(ByVal x As Boolean)
Application.ScreenUpdating = x
Application.EnableEvents = x
End Sub


Function BrowseForFolder(Optional OpenAt As Variant) As Variant
     
  Dim ShellApp As Object
  Set ShellApp = CreateObject("Shell.Application"). _
    BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
     
    On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
    On Error GoTo 0
     
    Set ShellApp = Nothing
     
    Select Case Mid(BrowseForFolder, 2, 1)
        Case Is = ":"
            If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
        Case Is = "\"
            If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
        Case Else
            GoTo Invalid
        End Select
    Exit Function

Invalid:
   
    
ToggleStuff True
End Function

  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
Helaas, ik heb vanalles geprobeerd, maar ik stuit telkens op het punt:
als de bestandjes bestaan vul me de naam, en modified date van dat bestandje in in CEL C1 en D1 voor DE.
Als het bestandje ook bestaat in FR dan vul cel E1 en F1 enz.
En ik weet niet hoe ik die 2 properties kan opvragen van een file.

Iemand geniale ideeën?

Dit is mijn code tot nu toe.. (let niet op de slordigheid hoor :o)

Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Sub PopulateDirectoryList()
'dimension variables
Dim objFSO As FileSystemObject, objFolder As Folder
Dim objFile As File, strSourceFolder As String, x As Long, i As Long
Dim wbNew As Workbook, wsNew As Worksheet
Dim FolderDE As String
Dim FolderES As String
Dim FolderFR As String
Dim FolderNL As String
Dim FolderPT As String
Dim FolderRU As String
Dim intLen As Integer
Dim objFileDE As String
Dim objFileES As String
Dim objFileFR As String
Dim objFileNL As String
Dim objFilePT As String
Dim objFileRU As String


ToggleStuff False 'turn of screenupdating

Set objFSO = New FileSystemObject  'set a new object in memory
strSourceFolder = BrowseForFolder 'call up the browse for folder routine
FolderDE = "S:\SMP\Epos\Development\ettext\forms\VA\DE\"
FolderES = "S:\SMP\Epos\Development\ettext\forms\VA\ES\"
FolderFR = "S:\SMP\Epos\Development\ettext\forms\VA\FR\"
FolderNL = "S:\SMP\Epos\Development\ettext\forms\VA\NL\"
FolderPT = "S:\SMP\Epos\Development\ettext\forms\VA\PT\"
FolderRU = "S:\SMP\Epos\Development\ettext\forms\VA\RU\"
intLen = Len(objFileDE)

If strSourceFolder = "" Then Exit Sub

Workbooks.Add 'create a new workbook

Set wbNew = ActiveWorkbook
Set wsNew = wbNew.Sheets(1) 'set the worksheet
wsNew.Activate
'format a header
With wsNew.Range("A1:N1")
    .Value = Array("GB", "Modified Date GB", "DE", "Modified Date DE", "ES", "Modified Date ES", "FR", _
                   "Modified Date FR", "NL", "Modified Date NL", "PT", "Modified Date PT", "RU", "Modified Date RU")
    .Interior.ColorIndex = 15
    .Font.Bold = True
    .Font.Size = 10
End With

With Application.FileSearch
    .LookIn = strSourceFolder  'look in the folder browsed to
    .FileType = msoFileTypeAllFiles 'get all files
    .SearchSubFolders = True  'search sub directories
    .Execute  'run the search
           
    For x = 1 To .FoundFiles.Count 'for each file found, by the count (or index)
       i = x 'make the variable i = x
       If x > 60000 Then  'if there happens to be more than multipls of 60,000 files, then add a new sheet
          i = x - 60000  'set i to the right number for row placement below
          Set wsNew = wbNew.Sheets.Add(after:=Sheets(wsNew.Index))
          With wsNew.Range("A1:B1")
            .Value = Array("File", "Modified Date")
            .Interior.ColorIndex = 15
            .Font.Bold = True
            .Font.Size = 10
           End With

       End If
        On Error GoTo Skip 'in the event of a permissions error
          
        Set objFile = objFSO.GetFile(.FoundFiles(x)) 'set the object to get it's properties
         With wsNew.Cells(1, 1) 'populate the next row with the variable data
             .Offset(i, 0) = objFile.Name
             .Offset(i, 1) = objFile.DateLastModified

                  'Test if directory or file exists
        intLen = Len(objFile.Name)
        intLen = intLen - 6
        
        objFileDE = (Left(objFile.Name, intLen) & "DE.doc")
        objFileES = (Left(objFile.Name, intLen) & "ES.doc")
        objFileFR = (Left(objFile.Name, intLen) & "FR.doc")
        objFileNL = (Left(objFile.Name, intLen) & "NL.doc")
        objFilePT = (Left(objFile.Name, intLen) & "PT.doc")
        objFileRU = (Left(objFile.Name, intLen) & "RU.doc")

            If FileOrDirExists(FolderDE & objFileDE) Then
                    Range(i, 2) = objFileDE
                    Range(i, 3) = objFile.DateLastModified
            
            ElseIf FileOrDirExists(FolderES & objFileES) Then
                    Range(i, 4) = objFileES
                    Range(i, 5) = objFile.DateLastModified
            
            ElseIf FileOrDirExists(FolderFR & objFileFR) Then
                    Range(i, 6) = objFileFR
                    Range(i, 7) = objFile.DateLastModified
                    
            ElseIf FileOrDirExists(FolderNL & objFileNL) Then
                    Range(i, 8) = objFileNL
                    Range(i, 9) = objFile.DateLastModified
                    
            ElseIf FileOrDirExists(FolderPT & objFilePT) Then
                    Range(i, 10) = objFilePT
                    Range(i, 11) = objFile.DateLastModified
                    
            ElseIf FileOrDirExists(FolderRU & objFileRU) Then
                    Range(i, 12) = objFileRU
                    Range(i, 13) = objFile.DateLastModified
            
            End If
            
Set objFile = Nothing
             
         End With
          ' Next objFile
Skip:
'this is in case a Permission denied error comes up or an unforeseen error
'Do nothing, just go to next file
     Next x
     
     
wsNew.Columns("A:N").AutoFit

End With

'clear the variables
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
Set wsNew = Nothing
Set wbNew = Nothing
       
ToggleStuff True 'turn events back on
End Sub

Sub ToggleStuff(ByVal x As Boolean)
Application.ScreenUpdating = x
Application.EnableEvents = x
End Sub


Function BrowseForFolder(Optional OpenAt As Variant) As Variant
     
  Dim ShellApp As Object
  Set ShellApp = CreateObject("Shell.Application"). _
    BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
     
    On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
    On Error GoTo 0
     
    Set ShellApp = Nothing
     
    Select Case Mid(BrowseForFolder, 2, 1)
        Case Is = ":"
            If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
        Case Is = "\"
            If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
        Case Else
            GoTo Invalid
        End Select
    Exit Function

Invalid:
   
    
ToggleStuff True
End Function

Function FileOrDirExists(PathName As String) As Boolean
     'Macro Purpose: Function returns TRUE if the specified file
     '               or folder exists, false if not.
     'PathName     : Supports Windows mapped drives or UNC
     '             : Supports Macintosh paths
     'File usage   : Provide full file path and extension
     'Folder usage : Provide full folder path
     '               Accepts with/without trailing "\" (Windows)
     
    Dim iTemp As Integer
     
     'Ignore errors to allow for error evaluation
    On Error Resume Next
    iTemp = GetAttr(PathName)
     
     'Check if error exists and set response appropriately
    Select Case Err.Number
    Case Is = 0
        FileOrDirExists = True
    Case Else
        FileOrDirExists = False
    End Select
     
     'Resume error checking
    On Error GoTo 0
End Function

  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
Is er niemand die hier meer van weet :?

Of eventueel hoe ik van een string (met het volledige pad van het document).
De wijzigingsdatum van dat document in excel kan krijgen.

Daar ben ik waarschijnlijk ook al mee geholpen

[ Voor 73% gewijzigd door fopspeen op 07-10-2008 15:25 ]


  • F_J_K
  • Registratie: Juni 2001
  • Niet online

F_J_K

Moderator CSA/PB

Front verplichte underscores

Ik herkende niet echt een vraag, dat zullen we wel meer hebben gehad. Ik dacht dat de vraag was hoe Last modified te vinden maar objFile.DateLastModified staat er al :P Wat vraag je nu precies / waar loop je vast?

offtopic:
Je code wordt leesbaarder als je zinnige variabelenamen gebruikt ipv. x en i. En zinnig commentaar neerzet, je commentaar bij 'i = x' is het schoolvoorbeeld van slechte comments ;)

^ Goedbedoelde kritiek trouwens.


Edit: ah, je had je kick aangevuld. DateLastModified doet precies wat je vraagt.

(Ik heb hier trouwens geen Excel+VBA dus kan niet meekijken).

[ Voor 14% gewijzigd door F_J_K op 07-10-2008 15:55 ]

'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind' (Terry Pratchett, Eric)


  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
Even over je Offtopic..ja ik weet het, ben geen ervaren code schrijver.
Ik doe het begin gewoon zoals ik volgens de boeken leer, en dan pas ik gewoon mij neigen variatie toe. Maar bedankt ik zal het proberen in de toekomst :)

En inderdaad die date last modified staat er al, maar zodra ik dan de macro wil laten lopen krijg ik een run time error met de melding "File not found"

Ik zal er thuis even verder naar kijken. Ik heb namelijk iets gevonden over "Filedatetime(pathname)"
Daar ga ik even verder mee borduren :)

  • F_J_K
  • Registratie: Juni 2001
  • Niet online

F_J_K

Moderator CSA/PB

Front verplichte underscores

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
DateLastModified
Beschrijving

Geeft de datum en het tijdstip waarop het opgegeven bestand of de map 
het laatst is gewijzigd. Alleen-lezen.

Syntaxis

object.DateLastModified

Het object is altijd een File- of Folder-object.

Notities

De volgende code illustreert het gebruik van de eigenschap DateLastModified 
met een bestand:

Sub ShowFileAccessInfo(filespec)
    Dim fs, f, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(filespec)
    s = UCase(filespec) & vbCrLf
    s = s & "Gemaakt op: " & f.DateCreated & vbCrLf
    s = s & "Laatst benaderd op: " & f.DateLastAccessed & vbCrLf
    s = s & "Laatst gewijzigd op: " & f.DateLastModified
    MsgBox s, 0, "Informatie over bestandstoegang"
End Sub

DateLastModified zou prima moeten werken.

'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind' (Terry Pratchett, Eric)


  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
Ik had het al anders geprobeerd met "Filedatetime" sorry
De code is nu compleet en doet precies wat ik wil. Ik zal even uitleggen wat de bedoeling ervan was.

De bedoeling was Om een lijstje te generen in Excel met word documenten.
Deze word documenten hebben als enigste vershil een taal aanduiding. GB.Doc, DE.doc, NL.doc enz.
Van de taal engels waren alle bestandjes er. Daarna is gekeken of het bestandje er ook was in de talen DE of NL enz. En als dit was dan werd de bestandsnaam en wijzigingsdatum ook gevuld.

Daarna zijn alle lege veldjes rood gemaakt omdat ze er niet waren.
En wijzigingsdatums die ouder waren dan de wijzingsdatum van GB geel ter controle.

hier is mijn code:

Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
Option Explicit
Sub PopulateDirectoryList()
'dimension variables
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Dim strSourceFolder As String
Dim x As Long
Dim i As Long
Dim wbNew As Workbook
Dim wsNew As Worksheet
Dim intLen As Integer
Dim ChDate(6) As Date

Dim objFileDE As String
Dim objFileES As String
Dim objFileFR As String
Dim objFileNL As String
Dim objFilePT As String
Dim objFileRU As String
Dim FolderDE As String
Dim FolderES As String
Dim FolderFR As String
Dim FolderNL As String
Dim FolderPT As String
Dim FolderRU As String
Dim DocPathDE As String
Dim DocPathES As String
Dim DocPathFR As String
Dim DocPathNL As String
Dim DocPathPT As String
Dim DocPathRU As String

ToggleStuff False 'turn of screenupdating

Set objFSO = New FileSystemObject  'set a new object in memory
strSourceFolder = BrowseForFolder 'call up the browse for folder routine

'Set folders with the pathnames
FolderDE = "S:\SMP\Epos\Development\ettext\forms\VA\DE\"
FolderES = "S:\SMP\Epos\Development\ettext\forms\VA\ES\"
FolderFR = "S:\SMP\Epos\Development\ettext\forms\VA\FR\"
FolderNL = "S:\SMP\Epos\Development\ettext\forms\VA\NL\"
FolderPT = "S:\SMP\Epos\Development\ettext\forms\VA\PT\"
FolderRU = "S:\SMP\Epos\Development\ettext\forms\VA\RU\"

If strSourceFolder = "" Then Exit Sub

    Workbooks.Add 'create a new workbook
    
    Set wbNew = ActiveWorkbook
    Set wsNew = wbNew.Sheets(1) 'set the worksheet
    wsNew.Activate
        
    'format a header
        With wsNew.Range("A1:N1")
            .Value = Array("GB", "Modified Date GB", "DE", "Modified Date DE", "ES", "Modified Date ES", "FR", _
                                     "Modified Date FR", "NL", "Modified Date NL", "PT", "Modified Date PT", "RU", "Modified Date RU")
            .Interior.ColorIndex = 15
            .Font.Bold = True
            .Font.Size = 10
        End With

        With Application.FileSearch
                        .LookIn = strSourceFolder  'look in the folder browsed to
                        .FileType = msoFileTypeAllFiles 'get all files
                        .SearchSubFolders = True  'search sub directories
                        .Execute  'run the search
           
                        For x = 1 To .FoundFiles.Count 'for each file found, by the count (or index)
                        i = x 'i is the rowcount
                        If x > 60000 Then  'if there happens to be more than multipls of 60,000 files, then add a new sheet
                            i = x - 60000  'set i to the right number for row placement below
                                Set wsNew = wbNew.Sheets.Add(after:=Sheets(wsNew.Index))
                                With wsNew.Range("A1:B1")
                                    .Value = Array("File", "Modified Date")
                                    .Interior.ColorIndex = 15
                                    .Font.Bold = True
                                    .Font.Size = 10
                                End With

End If
    On Error GoTo Skip
          
    Set objFile = objFSO.GetFile(.FoundFiles(x)) 'set the object to get it's properties
        With wsNew.Cells(1, 1) 'populate the next row with the variable data
            .Offset(i, 0) = objFile.Name
            .Offset(i, 1) = objFile.DateLastModified
        End With
         
        'Change filename withe the right Language
        intLen = Len(objFile.Name)
        intLen = intLen - 6
        objFileDE = (Left(objFile.Name, intLen) & "DE.doc")
        objFileES = (Left(objFile.Name, intLen) & "ES.doc")
        objFileFR = (Left(objFile.Name, intLen) & "FR.doc")
        objFileNL = (Left(objFile.Name, intLen) & "NL.doc")
        objFilePT = (Left(objFile.Name, intLen) & "PT.doc")
        objFileRU = (Left(objFile.Name, intLen) & "RU.doc")
        
        'Folderpath and filename are merged
        DocPathDE = FolderDE & objFileDE
        DocPathES = FolderES & objFileES
        DocPathFR = FolderFR & objFileFR
        DocPathNL = FolderNL & objFileNL
        DocPathPT = FolderPT & objFilePT
        DocPathRU = FolderRU & objFileRU

            
            'If the file exists then fill the cells with the
            'Filename and the change date
            If FileOrDirExists(DocPathDE) Then
            ChDate(1) = FileSystem.FileDateTime(DocPathDE)
                With wsNew.Cells(1, 1)
                    .Offset(i, 2) = objFileDE
                    .Offset(i, 3) = ChDate(1)
                    If ChDate(1) < objFile.DateLastModified Then
                        Cells(i + 1, 4).Interior.ColorIndex = 6
                    End If
                End With

            End If
            
            If FileOrDirExists(DocPathES) Then
            ChDate(2) = FileSystem.FileDateTime(DocPathES)
                With wsNew.Cells(1, 1)
                    .Offset(i, 4) = objFileES
                    .Offset(i, 5) = ChDate(2)
                End With
                If ChDate(2) < objFile.DateLastModified Then
                    Cells(i + 1, 6).Interior.ColorIndex = 6
                End If
            End If
            
            If FileOrDirExists(DocPathFR) Then
            ChDate(3) = FileSystem.FileDateTime(DocPathFR)
                With wsNew.Cells(1, 1)
                    .Offset(i, 6) = objFileFR
                    .Offset(i, 7) = ChDate(3)
                End With
                If ChDate(3) < objFile.DateLastModified Then
                    Cells(i + 1, 8).Interior.ColorIndex = 6
                End If
            End If
            
            If FileOrDirExists(DocPathNL) Then
            ChDate(4) = FileSystem.FileDateTime(DocPathNL)
                With wsNew.Cells(1, 1)
                    .Offset(i, 8) = objFileNL
                    .Offset(i, 9) = ChDate(4)
                End With
                If ChDate(4) < objFile.DateLastModified Then
                    Cells(i + 1, 10).Interior.ColorIndex = 6
                End If
            End If
            
            If FileOrDirExists(DocPathPT) Then
            ChDate(5) = FileSystem.FileDateTime(DocPathPT)
                With wsNew.Cells(1, 1)
                    .Offset(i, 10) = objFilePT
                    .Offset(i, 11) = ChDate(5)
                End With
                If ChDate(5) < objFile.DateLastModified Then
                    Cells(i + 1, 12).Interior.ColorIndex = 6
                End If
            End If
            
            If FileOrDirExists(DocPathRU) Then
            ChDate(6) = FileSystem.FileDateTime(DocPathRU)
                With wsNew.Cells(1, 1)
                    .Offset(i, 12) = objFileRU
                    .Offset(i, 13) = ChDate(6)
                End With
                If ChDate(6) < objFile.DateLastModified Then
                    Cells(i + 1, 14).Interior.ColorIndex = 6
                End If
            End If
                    
    On Error GoTo Skip
Skip:
'this is in case a Permission denied error comes up or an unforeseen error
'Do nothing, just go to next file
     Next x
     
'Autofit the Columns
wsNew.Columns("A:N").AutoFit

'Fill the Cell red if it is empty
Range("A2:N2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
    Formula1:="="""""
Selection.FormatConditions(1).Interior.ColorIndex = 3

End With

'clear the variables
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
Set wsNew = Nothing
Set wbNew = Nothing
       
ToggleStuff True 'turn events back on
End Sub

Sub ToggleStuff(ByVal x As Boolean)
Application.ScreenUpdating = x
Application.EnableEvents = x
End Sub

Function BrowseForFolder(Optional OpenAt As Variant) As Variant
     
  Dim ShellApp As Object
  Set ShellApp = CreateObject("Shell.Application"). _
    BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
     
    On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
    On Error GoTo 0
     
    Set ShellApp = Nothing
     
    Select Case Mid(BrowseForFolder, 2, 1)
        Case Is = ":"
            If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
        Case Is = "\"
            If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
        Case Else
            GoTo Invalid
        End Select
    Exit Function

Invalid:
    
ToggleStuff True
End Function

Function FileOrDirExists(PathName As String) As Boolean
     
    Dim iTemp As Integer
     
     'Ignore errors to allow for error evaluation
    On Error Resume Next
    iTemp = GetAttr(PathName)
     
     'Check if error exists and set response appropriately
    Select Case Err.Number
    Case Is = 0
        FileOrDirExists = True
    Case Else
        FileOrDirExists = False
    End Select
     
     'Resume error checking
    On Error GoTo 0
End Function

  • F_J_K
  • Registratie: Juni 2001
  • Niet online

F_J_K

Moderator CSA/PB

Front verplichte underscores

Ik begrijp dat je er uit bent? Dank voor de feedback :)

Even een klein detail: je noemt de 6 talen steeds los, maar neemt een array van 6 dates. Is dat bewust gedaan? Het klinkt als een v.w.b. onderhoud vervelende oplossing (goed opletten als je ooit een taal toevoegt of verandert).

Als het in het kader van nog leren is, hierbij juist mijn complimenten voor de, vergeleken met het gemiddelde, al goede kwaliteit :* Dan zal ik mijn (voor)oordelen over goto en over 'exit function' achterwege laten :+

'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind' (Terry Pratchett, Eric)


  • fopspeen
  • Registratie: Februari 2008
  • Laatst online: 10-08-2023
Ja inderdaad ik ben dit eigelijk nog an het leren. En door dit soort dingen leer ik natuurlijk nog meer erover :) En graag gedaan over de feedback. Bedankt voor al je reacties!;)
Pagina: 1