usage: CopyPdfFilesInSrcDir2TargDir [source Folder], [Target Folder]
Code:
Public Sub CopyPdfFilesInSrcDir2TargDir(ByVal pvDir, ByVal pvTargDir)
Dim fso, oFolder, oFile, vFile
Dim sTxt As String, sFile As String
Dim acc As Access.Application
Dim control As Office.CommandBarControl
Dim bRun As Boolean
Dim i As Integer
On Error GoTo errGetFiles
'fix targ dir name
If Right(pvTargDir, 1) <> "\" Then pvTargDir = pvTargDir & "\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(pvDir)
Set acc = New Access.Application
For Each oFile In oFolder.Files
If InStr(oFile.Name, ".pdf") > 0 Then 'only pdf files
vTargFile = pvTargDir & oFile.Name
Copy1File oFile, vTargFile
End If
Next
Endit:
Set oFile = Nothing
Set oFolder = Nothing
Set fso = Nothing
Set acc = Nothing
Set control = Nothing
MsgBox "Done"
Exit Sub
errGetFiles:
MsgBox Err.Description, , Err
Resume Endit
End Sub
Public Function Copy1File(ByVal pvSrc, ByVal pvTarg) As Boolean
Dim fso
On Error GoTo errMake
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile pvSrc, pvTarg
Copy1File = True
Set fso = Nothing
Exit Function
errMake:
'MsgBox Err.Description & vbCrLf & pvSrc, , "Copy1File(): " & Err
debug.print "err: " & pvSrc
Set fso = Nothing
End Function