I have looked through the forum but couldn't find what I am looking for.
Anybody has a code where it looks for defined specific names on one folder and then copies it to another folder.
any help would be greatly appreciated!
I have looked through the forum but couldn't find what I am looking for.
Anybody has a code where it looks for defined specific names on one folder and then copies it to another folder.
any help would be greatly appreciated!
![]()
Sub MoveFiles() Dim SrcPath As String Dim DestPath As String Dim FN As String Dim FilterString As String 'Be sure to include trailing backslash SrcPath = "C:\Users\owner\Documents\" DestPath = "C:\Users\owner\Documents\Dest\" FilterString = "*.xls?" FN = Dir(SrcPath & FilterString) If FN <> "" Then Do 'Name SrcPath & FN As DestPath & FN 'Moves the file FileCopy SrcPath & FN, DestPath & FN 'Copies the file FN = Dir Loop Until FN = "" End If End Sub
David
(*) Reputation points appreciated.
Change filterstring to any legal wildcard pattern.
or just this code![]()
FilterString = "RB?.pdf"
![]()
Name SrcPath & "RB1.pdf" As DestPath & "RB1.pdf" 'Moves the file Name SrcPath & "RB2.pdf" As DestPath & "RB2.pdf" 'Moves the file
Last edited by Tinbendr; 06-21-2016 at 04:07 PM.
![]()
Sub CommandButton19_Click() ' import roof profiles Dim SrcPath As String Dim DestPath As String Dim FN As String Dim FilterString As String 'Be sure to include trailing backslash SrcPath = SrceFile3 = "M:\CA\Jobs2016\" & TextBox3 DestPath = "S:\PDF_Jobs\" & ComboBox1 & "\" & ComboBox2 & "\" & ComboBox3 FilterString = "" FN = Dir(SrcPath & FilterString) If FN <> "" Then Do Name SrcPath & "RB1.pdf" As DestPath & "RB1.pdf" 'Moves the file Name SrcPath & "RB2.pdf" As DestPath & "RB2.pdf" 'Moves the file FileCopy SrcPath & FN, DestPath & FN 'Copies the file FN = Dir Loop Until FN = "" End If End Sub End Sub
Runs but doesn't do anything
![]()
Sub CommandButton19_Click() ' import roof profiles Dim SrcPath As String Dim DestPath As String 'Be sure to include trailing backslash SrcPath = SrceFile3 = "M:\CA\Jobs2016\" & TextBox3 & "\" DestPath = "S:\PDF_Jobs\" & ComboBox1 & "\" & ComboBox2 & "\" & ComboBox3 & "\" 'Makes sure file exists before proceeding. FN = Dir(SrcPath & "RB1.PDF") If FN <> "" Then Name SrcPath & "RB1.pdf" As DestPath & "RB1.pdf" 'Moves the file Name SrcPath & "RB2.pdf" As DestPath & "RB2.pdf" 'Moves the file End If End Sub
Thanks for the help, but It does the same thing. Maybe I am doing something wrong, dunno.
Add a line to see what path name you're generating.
F8 and step through the code until you pass the debug line. (Be sure to turn on the immediate window.)
Make sure the name shown matches the actual path.![]()
FN = Dir(SrcPath & "RB1.PDF") Debug.Print SrcPath & "RB1.PDF"
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks