Consulting

Results 1 to 4 of 4

Thread: Move file by vba

  1. #1

    Move file by vba

    check wheather file is located in C:\Users\srk\Desktop
    file name is Book1.xlsb
    if it located then do nothing and if not then file will be located in C:\Users\srk\Desktop\Files
    move the file from here C:\Users\srk\Desktop\Files
    to C:\Users\srk\Desktop
    this i have to do by vba

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi imrankhan!
    Something like below:
    Sub test()
    Dim pth$, flName$
    pth = "C:\Users\srk\Desktop\"
    flName = "Book1.xlsb"
    If Dir(pth & flName) = "" Then
      Name pth & "Files\" & flName As pth & flName
    End If
    End Sub

  3. #3
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test()
        Dim myFile As String
        Dim pFld As String
        
        myFile = "C:\Users\srk\Desktop\Files\Book1.xlsb"
        
        With CreateObject("scripting.filesystemobject")
            If Not .fileexists(myFile) Then Exit Sub
            pFld = .getparentfoldername(.getfile(myFile).parentfolder) & "\"
            If .fileexists(pFld & .getfilename(myFile)) Then Exit Sub
            .MoveFile myFile, pFld
        End With
        
    End Sub

  4. #4
    Thnx Mana Sir and 1976 Sir for giving ur Precious Time and Great Support to this Post
    Have a Great Day Sir
    Problem Solved

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
  •