Page 2 of 2

Re: :ต้องการ rename file in folder:

Posted: Mon Oct 30, 2017 3:54 pm
by logic
แบบนี้ได้ไหมครับ :?:

ผมใส่ "\" เข้าไปช่วย

Code: Select all

Sub DoSomething()
    Dim rAll As Range
    Dim r As Range
    With Sheets("List")
        Set rAll = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    End With
    For Each r In rAll
         MyPath = r.Value
         MyFile = r.Offset(0, 1).Value
         NewName = r.Offset(0, 2).Value
         If Dir(MyPath & "\" & MyFile) <> "" Then
             Name MyPath & "\" & MyFile As MyPath & "\" & NewName
         End If
     Next r
End Sub

Re: :ต้องการ rename file in folder:

Posted: Mon Oct 30, 2017 4:49 pm
by puriwutpokin
หรือปรับตรงนี้

Code: Select all

MyPath = r.Value & "\"

Re: :ต้องการ rename file in folder:

Posted: Mon Oct 30, 2017 5:15 pm
by parakorn
มันขึ้นแบบนี้ครับ แปลว่าต้องเปิดไฟล์ทั้งหมดไว้ ถึงจะทำการแก้ชื่อได้ใช่ไหมครับ :shock:

Re: :ต้องการ rename file in folder:

Posted: Mon Oct 30, 2017 6:24 pm
by parakorn
ได้รับความช่วยเหลือ แก้ไขเรียบร้อยแล้วนะครับ

Code: Select all

Sub DoSomething()
    Dim rAll As Range
    Dim r As Range
    On Error Resume Next
    With Sheets("List")
        Set rAll = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    End With
    For Each r In rAll
         MyPath = r.Value
         MyFile = r.Offset(0, 1).Value
         NewName = r.Offset(0, 2).Value
         If Dir(MyPath & "\" & MyFile) <> "" Then
             Name MyPath & "\" & MyFile As MyPath & "\" & NewName
         End If
     Next r
     MsgBox "Finish", vbInformation
End Sub
:D :D