Hi, I would really like it if you help me:
I have this code:
This code renames files within a folder, but for that the macro has to be within this folder.
I wish you would help me to replace the variable "mydir" to ask me which folder I want to rename the files.
thanks for your help.
I have this code:
Code:
Option Explicit
Sub rename_5()
Dim NewName As String, mydir As String, objFile As Object
Dim Last_name As String, id As String, b As String, m As String
mydir = Application.ThisWorkbook.Path
id = Range("e2").Value
b = Range("f2").Value
m = Range("g2").Value
With CreateObject("Scripting.FileSystemObject")
For Each objFile In .GetFolder(mydir).Files
If objFile.Name = id & "_" & "tkp" & n & "_tkl" & b & "_CI.xls" Then _
NewName = "CI_tkp" & b & "_" & id & ".xls"
If InStr(objFile.Name, "4t_SHOT_") Then _
NewName = id & "_4t_SHOT_" & Format(Date, "DDMMYYYY") & ".zip"
If objFile.Name = id & "_tkp" & n & "_tkl" & b & "_norm" & ".xml" Then _
NewName = id & "_Plan_" & Format(Date, "DDMMYYYY") & ".xml"
If Len(Dir(mydir & "\" & NewName)) = 0 Then objFile.Name = NewName
Next
End With
MsgBox "Done"
End Sub
This code renames files within a folder, but for that the macro has to be within this folder.
I wish you would help me to replace the variable "mydir" to ask me which folder I want to rename the files.
thanks for your help.
Last edited by a moderator: