VBA | Datei umbenennen aber Pfadangabe relativ
05.03.2008 11:01:00
oPabst
ich möchte gerne in einem script den Dateinamen umbenennen lassen.
Ich habe aber als Pfadangabe in meiner Variablen einen relativen Bezug.
Meine bisher gefundenen Lösungen haben aber alle absolute Bezüge.
Gibt es sowas wie - Name oldDatei as newDatei - auch mit relativem Bezug?
Gruß
Oliver
Sub ChangeHypes()
Dim iRow As Integer, iRowL As Integer, iChar As Integer
Dim sFile As String
Dim sPath As String
Dim sDatei As String
Dim newDatei As String
iRowL = Cells(Rows.count, 6).End(xlUp).Row
sTxt = Format(Cells(iRowL, 2).Value, "000") & "-" & Format(Cells(iRowL, 4).Value, "000") & "-" & _
_
Format(Cells(iRowL, 6).Value, "00000") & "_"
sPath = Cells(iRowL, 12).Hyperlinks(1).Address
sFile = Cells(iRowL, 12).Hyperlinks(1).Address
For iChar = Len(sFile) To 1 Step -1
If Mid(sFile, iChar, 1) = "/" Then Exit For
Next iChar
sFile = Right(sFile, Len(sFile) - iChar)
sPath = Left(sPath, Len(sPath) - Len(sFile))
Cells(iRowL, 12).Hyperlinks(1).Address = sPath & sTxt & sFile
sDatei = sPath & sFile
newDatei = sPath & sTxt & sFile
Const csMsg As String = "Datei existiert, überschreiben?"
On Error GoTo ERRORHANDLER
Name sDatei As newDatei
MsgBox "Datei wurde umbenannt!", vbInformation
Exit Sub
ERRORHANDLER:
If Err = 58 Then
Beep
If MsgBox(csMsg, vbQuestion + vbYesNo) = vbNo Then Exit Sub
Resume
ElseIf Err = 53 Then
Beep
MsgBox "Datei nicht gefunden!"
End If
End Sub