Results 1 to 10 of 27

Thread: VBA Dir File Copy and Paste: Check if file exists then copy file from one directory to another. Bat File

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Quote Originally Posted by fixer View Post
    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
    Last edited by DocAElstein; 03-27-2020 at 09:45 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Replies: 85
    Last Post: 06-09-2020, 05:58 PM
  2. Replies: 4
    Last Post: 05-08-2014, 10:12 PM
  3. Replies: 7
    Last Post: 08-28-2013, 12:57 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •