create folder datewise and copy file in it.

raviroyalnew

New Member
Joined
Apr 23, 2018
Messages
4
Hello,

Please suggest, where I am wrong.



Code:
Sub folder()


Dim sFolderName As String, set_Path As String, name As String, datpath As String
Dim FromPath As String
Dim FSO As Object
Set fs = CreateObject("Scripting.FileSystemObject")


FromPath = "C:\Users\sharr12\Desktop\Suivi\2132_sheet_suivi.xlsx"  '<< Change


set_Path = "C:\Users\sharr12\Desktop\Suivi\Fact Bakup\Suivi Fact_Backup_"
sFolderName = Format(Now(), "mm-dd-yy")


[name] = (set_Path & sFolderName)
datpath = [name]


If Error <> 0 Then
'MsgBox " Folder exists", vbInformation, "EOD Report Filter" 'Resume Next if folder exists
End If
On Error Resume Next
fs.CreateFolder [name]


'FileCopy "C:\Users\sharr12\Desktop\Suivi\2132_sheet_suivi.xlsx" & [name]
'FSO.CopyFile Source:=FromPath & FileExt, Destination:=[name]


Dim SourceFile, DestinationFile
    Dim sourcepath
    Dim destinationpath
    
SourceFile = "C:\Users\sharr12\Desktop\Suivi\2132_sheet_suivi.xlsx"
destinationpath = datpath
    
SourceFile = "2132_sheet_suivi.xlsx" ' Define source file name.
DestinationFile = "2132_sheet_suivi.xlsx" ' Define target file name.




FileCopy SourceFile, datpath ' Copy source to target.






End Sub
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi & welcome to MrExcel
How about
Code:
Sub MyFolder()
   Dim sFolderName As String, set_Path As String, fname As String, datpath As String
   Dim FromPath As String
   
   fname = "2132_sheet_suivi.xlsx"
   FromPath = "C:\Users\sharr12\Desktop\Suivi\"  '<< Change
   
   set_Path = "C:\Users\sharr12\Desktop\Suivi\Fact Bakup\Suivi Fact_Backup_"
   sFolderName = format(Date, "mm-dd-yy")
   
   datpath = set_Path & sFolderName & "\"
   
   If Dir(datpath, vbDirectory) = "" Then MkDir datpath
   FileCopy FromPath & fname, datpath & fname ' Copy source to target.
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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