AW: Datei mit bestimmten Namen suchen/kopieren
18.01.2010 17:53:15
Josef
Hallo Timothy,
bitte das nächste mal gleich mit der ganzen "Wahrheit" herausrücken.
Sub copyFile()
Dim objFSO As Object, rng As Range
Dim strFileToCopy, strNewFile As String, strOldPath As String, strNewPath As String
Dim lngC As Long
strOldPath = "E:\Temp\" 'Verzeichnis in dem die Datei liegt
strNewPath = "E:\Temp\Test\" 'Verzeichnis in welches kopiert werden soll
With ActiveSheet
For Each rng In Range("A1:A5") 'Bereich anpassen!
strFileToCopy = rng 'Zelle mit dem Namen
strFileToCopy = strFileToCopy & ".mpr" 'Suffix anhängen
lngC = 1
If Dir(strOldPath & strFileToCopy, vbNormal) <> "" Then
Do
strNewFile = Left(strFileToCopy, InStr(1, strFileToCopy, ".") - 1) & _
IIf(lngC > 1, "_" & CStr(lngC), "") & Mid(strFileToCopy, _
InStrRev(strFileToCopy, "."))
lngC = lngC + 1
Loop While Dir(strNewPath & strNewFile, vbNormal) <> ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.copyFile strOldPath & strFileToCopy, strNewPath & strNewFile
End If
Next
End With
Set objFSO = Nothing
Set rng = Nothing
End Sub
Gruß Sepp