Hello Experts - I have below code which transfers the file (Gross Contribution Report) inside the subfolder (and override the same file inside this subfolder). However, nothing is happening whenever i'm running below code. Can someone help me understand what's wrong. For visualization purposes. I have a main folder named "Reports" inside this folders are subfolders. And inside these subfolders, there's a file (Gross Contribution Report) and another subfolder named "Previous FF". What I wanted to do is to transfer the file inside the Previous FF folder and override the file inside it.
Code:
Sub Test()
Dim F As String
Dim Folder As String
Dim path As String
Set objFSO = CreateObject("scripting.filesystemobject")
mFolder = Environ("USERPROFILE") & "\Desktop\Reports\" '-----------------do not need to change this path----
Set mainfolder = objFSO.GetFolder(mFolder)
On Error Resume Next
For Each mySubfolder In mainfolder.SubFolders '--this will give you the path of subfolders-----
'Debug.Print mysubfolder
cname = Right(mySubfolder, Len(mySubfolder) - Len(mFolder)) '----to find out the country name----
'Debug.Print cname
F = "Gross Contribution Report" '----mention the name of your file---
sourcelocation = mySubfolder & cname & F & ".xlsx"
Destination = mFolder & cname & "\Previous FF\" '----This is the destination for archive file which I have taken inside country folder------
'Debug.Print sourcelocation
'Debug.Print Destination
objFSO.movefile sourcelocation, Destination
Next
End Sub