copy paste a file if its not present & if its present then do nothing

agog12

Board Regular
Joined
Jan 23, 2018
Messages
104
my file name is 4.xlsx
i have to copy this file and paste it to another path( if 4.xlsx file doesn't exist then copy paste it to C:\Users\WolfieeeStyle\Desktop/sholtan , but if file is there in the path C:\Users\WolfieeeStyle\Desktop/sholtan then do nothing)
i want to do this by vba so plz have a look sir and help me in solving this problem sir
file is located at C:\Users\WolfieeeStyle\Desktop/4.xlsx and we have to copy this file and paste it to C:\Users\WolfieeeStyle\Desktop/sholtan
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You should be able to make use of FileSystemObject for this

Below link is an excellent source for you to read and learn about it

 
Upvote 0
Bro i saw the code that code is adavanced code and i dont want that i dont want any msgbox
plz help me in solving this problem
 
Upvote 0
You could try this method which works for me
- amend to match your folder structure

VBA Code:
Sub CopyMyFile()
    Const oldPath = "C:\TestFolder\SubFolder1\4.xlsx "
    Const newPath = "C:\TestFolder\SubFolder2\4.xlsx "
    If Dir(newPath) = "" Then FileCopy oldPath, newPath
End Sub
 
Upvote 0
Another method which also works

VBA Code:
Sub CopyMyFile2()
    Dim wb As Workbook
    Const oldPath = "C:\TestFolder\SubFolder1\4.xlsx "
    Const newPath = "C:\TestFolder\SubFolder2\4.xlsx "

    If Dir(newPath) = "" Then
        Set wb = Workbooks.Open(oldPath)
        wb.SaveAs (newPath)
        wb.Close False
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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