Hi,
i want to copy the list of files from A column and below macro was copied but it was not looping to copied command, can any one help me....
Code
Option Explicit
Sub CopyFiles()
Dim iRow As Integer ' ROW COUNTER.
Dim SourcePath As String
Dim DestinationPath As String
Dim sFileType As String
Dim bContinue As Boolean
bContinue = True
iRow = 2
' THE SOURCE AND DESTINATION FOLDER WITH PATH.
SourcePath = InputBox("PLEASE ENTER PATH", "SOURCE PATH")
DestinationPath = InputBox("PLEASE ENTER PATH", "DESTINATION PATH")
sFileType = ".docx" 'TRY WITH OTHER FILE TYPES LIKE ".pdf".
sFileType = ".rtf"
' LOOP THROUGH COLUMN "B" TO PICK THE FILES.
While bContinue
If Len(Range("A" & CStr(iRow)).Value) = 0 Then ' DO NOTHING IF THE COLUMN IS BLANK.
MsgBox "Process executed" ' DONE.
bContinue = False
Else
' CHECK IF FILES EXISTS.
If Len(Dir(SourcePath & Range("B" & CStr(iRow)).Value & sFileType)) = 0 Then
Range("B" & CStr(iRow)).Value = "Does Not Exists"
Range("B" & CStr(iRow)).Font.Bold = True
Else
Range("B" & CStr(iRow)).Value = "Copied"
Range("B" & CStr(iRow)).Font.Bold = False
If Trim(DestinationPath) <> "" Then
Dim objFSO
Set objFSO = CreateObject("scripting.filesystemobject")
' CHECK IF DESTINATION FOLDER EXISTS.
If objFSO.FolderExists(DestinationPath) = False Then
MsgBox DestinationPath & " Does Not Exists"
Exit Sub
End If
'*****
' HERE I HAVE INCLUDED TWO DIFFERENT METHODS.
' I HAVE COMMENTED THE SECOND METHOD. TO THE SEE THE RESULT OF THE
' SECOND METHOD, UNCOMMENT IT AND COMMENT THE FIRST METHOD.
' METHOD 1) - USING "CopyFile" METHOD TO COPY THE FILES.
objFSO.CopyFile Source:=SourcePath & Range("B" & CStr(iRow)).Value & _
sFileType, Destination:=DestinationPath
' METHOD 2) - USING "MoveFile" METHOD TO PERMANENTLY MOVE THE FILES.
'objFSO.MoveFile Source:=sSourcePath & Range("B" & CStr(iRow)).Value & _
sFileType, Destination:=sDestinationPath
'*****
End If
End If
End If
iRow = iRow + 1 ' INCREMENT ROW COUNTER.
Wend
End Sub
Display More
Range is "Column A" and Msg box is "Column B" Format types .doc, .rtf,.docx , .pdf
Please anyone help me in this regards or if possible make it as easier to loop and thanks in advance.
<img src="https://www.ozgrid.com/forum/core/images/smilies/emojione/263a.png" alt=":)" class="smiley" srcset="https://www.ozgrid.com/forum/core/images/smilies/emojione/[email protected] 2x" height="23" data-tooltip="smile" id="wscSmiley_0_0">
Code
Range is "Column A" and Msg box is "Column B" Format types .doc, .rtf,.docx , .pdf
Please anyone help me in this regards or if possible make it as easier to loop and thanks in advance.
<img src="https://www.ozgrid.com/forum/core/images/smilies/emojione/263a.png" alt=":)" class="smiley" srcset="https://www.ozgrid.com/forum/core/images/smilies/emojione/[email protected] 2x" height="23" data-tooltip="smile" id="wscSmiley_0_0">