need script for excel vba

shariq

New Member
Joined
Mar 10, 2022
Messages
30
Office Version
  1. 2010
Platform
  1. Windows
i need your help expert i need a vba script for moving file into the folder please read my screnshot are give below.
 

Attachments

  • IMG-20230129-WA0006.jpg
    IMG-20230129-WA0006.jpg
    168.8 KB · Views: 9

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Give this a shot. You will need to change the folder paths in the code to match the folder names on your computer.

VBA Code:
Sub MOVEFILES()
Dim uFiles As Object:       Set uFiles = CreateObject("Scripting.FileSystemObject")
Dim uFolders As Object:     Set uFolders = CreateObject("Scripting.FileSystemObject")
Dim uFilePath As String:    uFilePath = "C:\Users\UserName\Desktop\User Files"
Dim uFolderPath As String:  uFolderPath = "C:\Users\UserName\Desktop\User Folders"
Dim ufol As Object, ufil As Object, fil As Object

Set ufil = uFiles.getfolder(uFilePath)
Set ufol = uFiles.getfolder(uFolderPath)

For Each fil In ufil.Files
    GetMatch ufol, fil
Next fil

End Sub

Sub GetMatch(fol As Object, fil As Object)
Dim f As Object

For Each f In fol.subFolders
    If Split(f.Name, " ")(0) = Split(fil.Name, " ")(0) Then
        Name fil.Path As Join(Array(f.Path, fil.Name), "\")
        Exit Sub
    End If
Next f
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top