+ Reply to Thread
Results 1 to 3 of 3

Can I user input to seek out particular files and copy/move them?

  1. #1
    silkworm
    Guest

    Can I user input to seek out particular files and copy/move them?

    The files I work with have names like : "16A-11H1H_JMDI4_265PH.CHP"
    where "265PH" is a project name.

    I want to write a Excel VBA scrpit, to prompt user to enter a project
    name such as "265PH" and have the program to look into a directory to
    copy any files with those characters in it. I've read about the

    FileCopy Statement
    or
    FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc",
    "c:\tempfolder\"

    I think I need do something like "c:\mydocuments\letters\*265PH.CHP",
    but "265PH" needs to be a user specified input.

    My question is that how do I pass a string variable that contain the
    user input characters into the file name when the file name and path is
    in double qoutation marks?


    Thanks for the help


  2. #2
    Dave Peterson
    Guest

    Re: Can I user input to seek out particular files and copy/move them?

    Option Explicit
    Sub testme()

    Dim FSO As Scripting.FileSystemObject
    Dim ProjName As String

    ProjName = InputBox(Prompt:="Enter the project name")
    If ProjName = "" Then
    Exit Sub 'cancel
    End If

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set FSO = New Scripting.FileSystemObject

    FSO.CopyFile _
    Source:="C:\my documents\excel\" & "*" & ProjName & ".xls", _
    Destination:="C:\temp", _
    overwritefiles:=True

    End Sub



    silkworm wrote:
    >
    > The files I work with have names like : "16A-11H1H_JMDI4_265PH.CHP"
    > where "265PH" is a project name.
    >
    > I want to write a Excel VBA scrpit, to prompt user to enter a project
    > name such as "265PH" and have the program to look into a directory to
    > copy any files with those characters in it. I've read about the
    >
    > FileCopy Statement
    > or
    > FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc",
    > "c:\tempfolder\"
    >
    > I think I need do something like "c:\mydocuments\letters\*265PH.CHP",
    > but "265PH" needs to be a user specified input.
    >
    > My question is that how do I pass a string variable that contain the
    > user input characters into the file name when the file name and path is
    > in double qoutation marks?
    >
    > Thanks for the help


    --

    Dave Peterson

  3. #3
    silkworm
    Guest

    Re: Can I user input to seek out particular files and copy/move them?

    Thanks for the reply.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1