
Originally Posted by
fixer
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
Error you have
Desktop/
Should be
Desktop\
Very similar to your previous questions ( http://www.excelfox.com/forum/showth...ll=1#post12565 , http://www.excelfox.com/forum/showth...ll=1#post12566
)
So I have merged all the Threads together.
Same macro as here: http://www.excelfox.com/forum/showth...ll=1#post12566
….file is located at C:\Users\WolfieeeStyle\Desktop\4.xlsx, so Source is C:\Users\WolfieeeStyle\Desktop\4.xlsx , and we have to copy this file and paste it to C:\Users\WolfieeeStyle\Desktop\sholtan so Destination is C:\Users\WolfieeeStyle\Desktop\sholtan\4.xlsx
Code:
Sub VBACheckIfFileExists_ThenCopy() ' http://www.excelfox.com/forum/showthread.php/2424-VBA-Copy-and-Paste-Check-if-file-exists-then-copy-file-from-one-directory-to-another?p=13010&viewfull=1#post13010 http://www.excelfox.com/forum/showthread.php/2424-VBA-Check-if-file-exists-then-copy-file-from-one-directory-to-another
Dim StrDirBack As String ' see if file, 4.xlsx , is there in the path C:\Users\WolfieeeStyle\Desktop\sholtan
Let StrDirBack = Dir("C:\Users\WolfieeeStyle\Desktop\sholtan\4.xlsx", vbNormal)
If StrDirBack = "" Then ' if Dir("C:\Users\WolfieeeStyle\Desktop\sholtan\4.xlsx", vbNormal) = "" then file 4.xlsx is not at C:\Users\WolfieeeStyle\Desktop\sholtan
' case StrDirBack = "" file is located at C:\Users\WolfieeeStyle\Desktop\4.xlsx, so Source is C:\Users\WolfieeeStyle\Desktop\4.xlsx , and we have to copy this file and paste it to C:\Users\WolfieeeStyle\Desktop\sholtan so Destination is C:\Users\WolfieeeStyle\Desktop\sholtan
FileCopy Source:="C:\Users\WolfieeeStyle\Desktop\4.xlsx", Destination:="C:\Users\WolfieeeStyle\Desktop\sholtan\4.xlsx"
Else ' case StrDirBack <> ""
' if StrDirBack <> "" , then file is already there, so do nothing .... ... if file is there in the path C:\Users\WolfieeeStyle\Desktop\sholtan then do nothing
End If
End Sub
Bookmarks