I am trying to create a code to copy a pdf file from a folder to another folder keeping same name and everything.
when I type the file name in a textbox and click on a button I want the code to copy this file from a folder to another.
my code is copying ALL the files in the source folder to the destination folder and renaming it by the textbox name that I have typed (txtledger.value) & the file original name. I dont know how to fix it.
Sub CreatingFSO()
Dim MyFSO As FileSystemObject
Set MyFSO = New FileSystemObject
End Sub
Sub CopyFiles()
Dim MyFSO As FileSystemObject
Dim MyFile As File
Dim SourceFolder As String
Dim DestinationFolder As String
Dim MyFolder As Folder
Set MyFile = txtLedger.Value
SourceFolder = "F:\4-2022"
DestinationFolder = "F:\DELEGATION APPLICATION\" & MyFile
Set MyFSO = New Scripting.FileSystemObject
Set MyFolder = MyFSO.GetFolder(SourceFolder)
For Each MyFile In MyFolder.Files
MyFSO.CopyFile Source:=MyFSO.GetFile(MyFile), _
Destination:=DestinationFolder & MyFile.Name, Overwritefiles:=False
Next MyFile
End Sub
I'm new to this so I don't know how what to do. any help please?