Tuesday, 24 March 2015

Rename filename in XL VBA

Sub ChangeFilename()

Dim s1 As Worksheet

Dim strtpoint, end_point, i As Double

 

Set s1 = Worksheets("Data")

strtpoint = s1.Cells(2, 3)

end_point = s1.Cells(3, 3)

Dim FILEPATH As String

FILEPATH = s1.Cells(1, 3)

 

Dim oldfilename, newfilename As String

Dim filenum As String

 

For i = strtpoint To end_point

oldfilename = s1.Cells(i, 2)

newfilename = s1.Cells(i, 3)

 

 

    Name FILEPATH & oldfilename As FILEPATH & newfilename

  

Next i

End Sub