Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Jun 2003
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tag all files in directory? (Word 2000)

    Is there a way to tag/highlight all files in a folder without exiting word? I know that I can File/Open, Ctrl/Shift and mouse-click to tag all files, but I was wondering if there were a way to do this with keystrokes?

    I would like to write a macro that will transfer all of my files at the end of the day from folder D:Reports to folder D:Finished Reports. The only problem is that I cannot figure out how to tag all of the files at one time in order to incorporate the commands into my macro.

    There must be a way to do this?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Tag all files in directory? (Word 2000)

    In the File | Open dialog, you can press Tab a few times until the focus is in the files list, then Ctrl+A to select all files. But that is not the best way to transfer files.

    In the Visual Basic Editor, set a reference to Microsoft Scripting Runtime. You can then use the FileSystemObject, which has a CopyFile method:

    Sub Transfer()
    Dim fso As New Scripting.FileSystemObject
    fso.CopyFile "D:Reports*.doc", "D:Finished Reports"
    Set fso = Nothing
    End Sub

  3. #3
    Star Lounger
    Join Date
    Jun 2003
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tag all files in directory? (Word 2000)

    Thank you Hans for your help. Could you explain a little more about what you mean by:

    "In the Visual Basic Editor, set a reference to Microsoft Scripting Runtime. You can then use the FileSystemObject, which has a CopyFile method:"

    How would I go about setting a reference? Do I need to put something in Declarations? Also, I'm not sure what the FileSystemObject is either.

    I tried using the Tab/Ctrl A function, but it doesn't work for me.

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Tag all files in directory? (Word 2000)

    To set a reference to an external library in VBA, in the VB editor you select Tools, References and from the list of available References you can select the appropriate library, in this case Microsoft Scripting Runtime. This library is contained in a file called SCRRUN.DLL which is typically stored in the System32 subfolder of the directory which contains your windows OS installation (C:Windows or C:Winnt),

    The Scripting Runtime is a library of routines supplied by Microsoft for the manipulation of files and folders. It contains the FileSystemObject which enables you copy, move or delete files and folders and also the TextStream object which allows you to read from and write to text files.

    However you can use it without setting a reference in your VBA project and the following alteration to Hans' code should work, provided you have the library installed on your PC.

    Sub Transfer()
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile "D:Reports*.doc", "D:Finished Reports"
    Set fso = Nothing
    End Sub

    Andrew C

  5. #5
    Star Lounger
    Join Date
    Jun 2003
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tag all files in directory? (Word 2000)

    Thank you Andrew.

    The code worked, so I must have the library installed. One small problem though, is there a way to MOVE the files without keeping a copy in the main directory? I tried changing the CopyFile to MoveFile, but received an error message.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Tag all files in directory? (Word 2000)

    What is the exact code you used, and what is the text of the error message?

    fso.MoveFile "D:Reports*.doc", "D:Finished Reports"

    should work - I just tested it (with the names of existing folders on my PC).

  7. #7
    Star Lounger
    Join Date
    Jun 2003
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tag all files in directory? (Word 2000)

    I used the same code that Andrew had written, only exchanged copyfile with movefile.

    Sub Transfer ()

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.MoveFile "D:Reports*.doc", "D:Finished Reports"
    Set fso = Nothing
    End Sub

    I keep getting run-time error 70
    Permission Denied

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Tag all files in directory? (Word 2000)

    It would seem that either the files are in use (are they still open in Word?), or you don't have the permissions needed to remove the files from D:Reports.

  9. #9
    Star Lounger
    Join Date
    Jun 2003
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tag all files in directory? (Word 2000)

    Okay, a little embarassed, but delighted that it was so simple. I wasn't exiting the document before running the macro.

    Thank you for your help and insight Hans, and thank you again Andrew for your help as well!!!

Posting Permissions

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