+ Reply to Thread
Results 1 to 5 of 5

Copy a folders & files

  1. #1
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Copy a folders & files

    Hi
    I am trying to get a master purchase order sheet to copy and rename a set of folders and files contained within to a central location.
    The folders are in the 'Standard Documents Folder' and I am wanting these to copy to the main 'Contract' Folder on the server (at the minute I'm using a test folder 'Test').
    The code I have below so far is:

    Please Login or Register  to view this content.
    I am getting the error "Object Variable or With Block Variable not set" on the following code:

    Please Login or Register  to view this content.
    Can anyone see why?

    My next query when I can get this one sorted is to have the other excel files that are already on the copied files to be renamed in the same way (contract number etc, so RAMS would become C12345 RAMS etc).
    What would be the best way to do this?
    Kieran

  2. #2
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy a folders & files

    I've got it to work and save the master workbook as the cell values, I just need to sort the correct name and folder destination out now!

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy a folders & files

    Ahh I'm still getting the same error message
    "Run-time error '1004' Method 'SaveAs' of object'_workbook failed"

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy a folders & files

    I have played around a bit more and can get this to work when I "note" out the SaveAs code, press my button, go back into the code and remove the ' from the SaveAs code and then press the button again.
    Looking around on here and other sites, it is obviosuly giving the error as it can't find the folder I am asking the code to create and the save the file into this new folder.

    Is there a way around this?
    Kieran

    Please Login or Register  to view this content.


    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy a folders & files

    Anyone got any ideas?

    I have taken the SaveAs code out of the main code section now, put this into a separate module. Then added the call macro code to make this run within the main code section.

    It still gives the error as the SaveAs tries to run before the folders are created in the first section of code. How can I get around this?

    Kieran

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy multiple files in different folders
    By payalvj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2016, 06:57 AM
  2. Use Excel VBA to Copy multiple files from different source folders to different folders
    By mm1234mail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 01:17 PM
  3. Replies: 0
    Last Post: 05-26-2014, 07:47 PM
  4. How to copy and rename files in vba by searching multiple folders for files
    By razorace in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2014, 04:21 AM
  5. Replies: 1
    Last Post: 09-12-2013, 09:23 PM
  6. Create folders and move and copy files into that folders
    By vijaybharthi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2010, 04:01 AM
  7. Copy multiple files from folders
    By jeff p in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-30-2009, 02:27 AM

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