PDA

View Full Version : how to move xls files in same named folders by vba



m_vishal_c
09-27-2017, 07:54 PM
hi . how can i move excel files in same name folders by vba.
for example
i have abc.xls and " abc " folder .
xyz.xls and " xyz " folder. i have number of xls files and want to move these files to same name folders

I want to be done by vba

heaps thanks in advance

Bob Phillips
09-28-2017, 12:00 AM
Dim filename As String, path As String, newdir As String

path = "c:\Users\Bob\Downloads\"
filename = Dir(path & "*.xl*", vbNormal)
Do While filename <> ""

newdir = Left$(filename, InStrRev(filename, ".") - 1) & Application.PathSeparator
Name path & filename As newdir & filename
filename = Dir()
Loop

Set path as required