Using VBA To Search For Specified File Types

vsehijpal

New member
Local time
Today, 20:17
Joined
Mar 22, 2004
Messages
6
I'm looking to build a system that will have the functionality to search a specified location for a certain file type (.msg) and then move those files to another, shared, location.

I'm not sure where to begin with this one so all help is be appreciated
Thanks
Vin
 
You might try this:

Create a new Module and paste the following code into it, then save it as modMoveMsg:
Code:
Public Sub MoveMsg(ByVal sourcePath As String, ByVal destPath As String)

    Dim dirStr As String

    If Right(sourcePath, 1) <> "\" Then sourcePath = sourcePath & "\"
    If Right(destPath, 1) <> "\" Then destPath = destPath & "\"

    dirStr = Dir(sourcePath & "*.msg")

    Do While dirStr > ""
        FileCopy sourcePath & dirStr, destPath & dirStr
        Kill sourcePath & dirStr
        dirStr = Dir
    Loop

End Sub

Calling the sub with something like:
Call MoveMsg("C:\MyFolder\","G:\SharedFolder\")

...will move all the files with the .msg extension from C:\MyFolder\ to G:\SharedFolder\.
 
Thanks I'll try that
 

Users who are viewing this thread

Back
Top Bottom