Der Code mit der fortlaufenden Nummer funktioniert in Kombination mit Deinem so nicht... weil der FullPath enthält auch die Dateiendung, Entschuldigung.
Der Code unten macht einen neuen Namen wie der Windows-Explorer.
Andreas.
Function NewFileName(ByVal FullName As String) As String
'Return a filename that did not exists but begins with fullname
' i.E.: c:\temp\test.xla => c:\temp\test(1).xla
Dim i As Long, LeftParen As Long, RightParen As Long, DotPos As Long
Dim LeftPart As String, RightPart As String
If Dir$(FullName) <> "" Then
LeftParen = InStrRev(FullName, "(")
RightParen = InStrRev(FullName, ")")
On Error GoTo AddParen
i = Mid$(FullName, LeftParen + 1, RightParen - LeftParen - 1)
LeftPart = Left$(FullName, LeftParen)
RightPart = Mid$(FullName, RightParen)
GoTo Doit
AddParen:
DotPos = InStrRev(FullName, ".")
If DotPos = 0 Then
LeftPart = FullName & "("
RightPart = ")"
Else
LeftPart = Left$(FullName, DotPos - 1) & "("
RightPart = ")" & Mid$(FullName, DotPos)
End If
Doit:
Do
i = i + 1
NewFileName = LeftPart & i & RightPart
Loop Until Dir$(NewFileName) = ""
Else
NewFileName = FullName
End If
End Function