PDA

View Full Version : [SOLVED] Move file by vba



imrankhan
09-07-2019, 09:26 PM
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

大灰狼1976
09-07-2019, 10:19 PM
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

mana
09-07-2019, 10:49 PM
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

imrankhan
09-08-2019, 12:06 AM
Thnx Mana Sir and 1976 Sir for giving ur Precious Time and Great Support to this Post
Have a Great Day Sir
Problem Solved