Macro to copy specific files from Sub Folder to Folder

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,566
Office Version
  1. 2021
Platform
  1. Windows
I have several files in sub folders on a network "\\account\man\

The sub folders are for eg "\\ad\admin\BR1\

"\\ad\admin\BR2\

"\\ad\admin\sammy\

Etc


I would like all files that contain "Template 2020.xlsm to coy copy to this folder el BR Sales Report template 2020.xlsm

It would be appreciated if someone could provide me with code to do this
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I have tried to adapt code that I obtained ion the Web, but cannot get it to work



Copy Run Numbers templates from Network.xlsm


Code:
 Sub sbCopyingAFileReadFromSheet()

'Declaration
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String


'This is Your File Name which you want to Copy.You can change File name at A1.
sFile = Sheets("Main").Range("A1")

'Change to match the source folder path. You can change Source Folder name at B1.
sSFolder = Sheets("Main").Range("B1")

'Change to match the destination folder path. You can change Destination Folder name at B2.
sDFolder = Sheets("Main").Range("B2")

'Create Object for File System
Set FSO = CreateObject("Scripting.FileSystemObject")

'Checking If File Is Located in the Source Folder
If Not FSO.FileExists(sSFolder & sFile) Then
    MsgBox "Specified File Not Found in Source Folder", vbInformation, "Not Found"

'Copying If the Same File is Not Located in the Destination Folder
ElseIf Not FSO.FileExists(sDFolder & sFile) Then
FSO.CopyFile (sSFolder & sFile), sDFolder, True
MsgBox "Specified File Copied to Destination Folder Successfully", vbInformation, "Done!"
Else
MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"
End If

End Sub

It would be appreciated if someone can kindly asssist me
 
Upvote 0
I had a typo in post #1

I have several files in sub folders on a network "\\account\man\

The sub folders are for eg "\\account\man\BR1\

"\\account\admin\BR2\

"\\account\admin\sammy\

Etc


I would like all files that contain "Template 2020.xlsm to be copied from the sub-folders for eg BR Sales Report template 2020.xlsm to C:\Sales Reports\


I have also posted on link below


 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,945
Members
449,198
Latest member
MhammadishaqKhan

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