+ Reply to Thread
Results 1 to 4 of 4

Macro to copy workbooks from one location to another.

  1. #1
    Dtown Dawg
    Guest

    Macro to copy workbooks from one location to another.

    I have a folder that contains about 100 workbooks and these workbooks have to
    always be there.
    What I do now is go to that folder copy all the workbooks and then past them
    into a folder on my desktop.

    Is there a macro or batch file or something that I can creat that all I have
    to do is hit "run" or something and have it go out, copy everythign in that
    folder and past it to the folder on my desktop?
    Thanks;
    The Dawg

  2. #2
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Try this:

    Sub copy_contents_of_folder()
    sourcepathname = "C:\MyFolder\"
    destpathname = "C:\WINNT\Profiles\MyUserName\Desktop\MyOtherFolder\"
    filemask = "*.xls"
    fname = Dir(sourcepathname & filemask, vbNormal)
    Do While fname <> ""
    FileCopy sourcepathname & fname, destpathname & fname
    fname = Dir()
    Loop
    End Sub

    Change the values of "sourcepathname" and "destpathname" to the relevant folders - don't forget the trailing \'s

    Hope it helps
    Col

  3. #3
    Dtown Dawg
    Guest

    Re: Macro to copy workbooks from one location to another.

    I'm having trouble getting this to work. Here is my code. I'm not getting any
    error:

    Sub copy_contents_of_folder()
    sourcepathname = "C:\Documents and
    Settings\dmobley\Desktop\JunkFolder\TESTEXCEL"
    destpathname = "C:\Documents and Settings\dmobley\My Documents\My Music"
    filemask = "*.xls"
    fname = Dir(sourcepathname & filemask, vbNormal)
    Do While fname <> ""
    FileCopy sourcepathname & fname, destpathname & fname
    fname = Dir()
    Loop
    End Sub

    "colofnature" wrote:

    >
    > Try this:
    >
    > Sub copy_contents_of_folder()
    > sourcepathname = "C:\MyFolder\"
    > destpathname =
    > "C:\WINNT\Profiles\MyUserName\Desktop\MyOtherFolder\"
    > filemask = "*.xls"
    > fname = Dir(sourcepathname & filemask, vbNormal)
    > Do While fname <> ""
    > FileCopy sourcepathname & fname, destpathname & fname
    > fname = Dir()
    > Loop
    > End Sub
    >
    > Change the values of "sourcepathname" and "destpathname" to the
    > relevant folders - don't forget the trailing \'s
    >
    > Hope it helps
    > Col
    >
    >
    > --
    > colofnature
    > ------------------------------------------------------------------------
    > colofnature's Profile: http://www.excelforum.com/member.php...o&userid=34356
    > View this thread: http://www.excelforum.com/showthread...hreadid=543080
    >
    >


  4. #4
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Couple of things - first, add "\" to the end of values in "sourcepathname" and "destpathname", and second, if you're copying anything other than spreadsheets you'll need to change the value of "filemask" to whatever the extension is for that type of file (e.g. "*.mp3", "*.jpg" etc)

    Col

+ 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