Option
Explicit
Private
Const
C_PATH
As
String
=
"C:\Users\Public\Documents"
Public
Sub
renameCsvFiles()
Dim
fso
As
New
FileSystemObject
If
Not
fso.FolderExists(C_PATH)
Then
MsgBox
"Verzeichnis existiert nicht."
, vbExclamation
GoTo
cleanUp
End
If
Dim
fold
As
Folder
Dim
f
As
File
On
Error
GoTo
cleanUp
Set
fold = fso.GetFolder(C_PATH)
For
Each
f
In
fold.Files
If
InStr(1, f.Name,
"NDGS"
, vbBinaryCompare)
Then
f.Copy f.ParentFolder.Path &
"\NDGS.csv"
,
False
f.Delete
False
ElseIf
InStr(1, f.Name,
"DGS"
, vbBinaryCompare)
Then
f.Copy f.ParentFolder.Path &
"\DGS.csv"
,
False
f.Delete
False
End
If
Next
f
On
Error
GoTo
0
cleanUp:
If
Err.Number > 0
Then
MsgBox
"Es ist leider ein Fehler aufgetreten."
& vbCrLf & _
"Fehlernummer: "
& Err.Number & vbCrLf & _
"Fehlerbeschreibung: "
& Err.Description, vbExclamation
End
If
If
Not
fold
Is
Nothing
Then
Set
fold =
Nothing
If
Not
fso
Is
Nothing
Then
Set
fso =
Nothing
End
Sub