+ Reply to Thread
Results 1 to 13 of 13

FileCopy function

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    FileCopy function

    I would like to transfer a template document to a folder that I am creating with VBA.

    I have been working on the FileCopy method but realised I cannot move a document I am using. Is there a method I can use to get around this?

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,367

    Re: FileCopy function

    An easy approach is two steps:

    FileCopy PathAndFileInfo, PathAndCopyInfo
    Kill PathAndFileInfo

    Or use the Move method of the FileSystemObject approach to file management:

    http://msdn.microsoft.com/en-us/libr...ffice.15).aspx
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: FileCopy function

    Cheers Bernie but I'm not trying to move the document. I am opening a user based document and someone uses it to set up a new user. When they do a new file path is created and a copy of the template document (held elsewhere) is copied into the new filepath with certain info added to the new copy.

    When you say fileinfo and copyinfo what d you mean, and is that the exact syntax?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: FileCopy function

    Why not just do SaveCopyAs?
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,367

    Re: FileCopy function

    Sorry, I misunderstood. I would just use:

    Thisworkbook.SaveAs "path and name", 52

    Like

    ThisWorkbook.SaveAs "M:\My Documents\New Folder\NewBookName.xlsm", 52 ' 52 = Macro Enabled workbook

    to the new file path - the workbook is saved in the new folder, and the template is no longer the activeworkbook. If you want the template to remain the activeworkbook, the use


    Thisworkbook.SaveCopyAs "M:\My Documents\New Folder\NewBookName.xlsm" 'Extension must match file type

  6. #6
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: FileCopy function

    Quote Originally Posted by shg View Post
    Why not just do SaveCopyAs?
    shg, because each document is specific to the user in regards to hidden info that is called upon.

  7. #7
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: FileCopy function

    Bernie,

    Folder 1 = Template doc I am attempting to copy into Folder 3 (which is the new folder I have created).
    Folder 2 = Version of the Folder 1 document that is being used

  8. #8
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: FileCopy function

    Sorry people, I still don't have a working solution to this issue?

  9. #9
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: FileCopy function

    I've tried something along these lines but it doesn't seem to be working

    Please Login or Register  to view this content.
    This is the value of GPath's cell BA4
    Please Login or Register  to view this content.
    Last edited by Sc0tt1e; 10-03-2014 at 09:13 AM.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: FileCopy function

    Why does this,
    Quote Originally Posted by scottie
    each document is specific to the user in regards to hidden info that is called upon
    preclude the use of SaveCopyAs?
    If posting code please use code tags, see here.

  11. #11
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: FileCopy function

    OK, now I've posted the code I can see how much of a mess this is. I will work on code and if I still have no luck will start afresh.

    If however someone can work out what I'm trying to do and suggest a solution that would be greatly appreciated.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: FileCopy function

    Where do you want to copy the workbook to?

    Is it the same path as the workbook, wbs, being opened?
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: FileCopy function

    [/QUOTE]Is it the same path as the workbook, wbs, being opened?[/QUOTE]

    The location the document to save to is as above, the location will not be the same as the location the workbook was opened from though.

    Template is saved at
    Please Login or Register  to view this content.
    document is called "Tyrant.xlsm"
    Every time a new member of staff is added to the HR database a new filepath is set up for them and a copy of the template document is added to this folder.
    Please Login or Register  to view this content.
    Multiple people can set up new users so the starting location of the document will differ depending on who is setting up new people. Also I had a problem trying to determine who was using each version so I have added some code to insert some initials into A1 of Sheet 1 and some changes here and there depending on job role, of the template being copied across so a copy of the version being used is no good due to the changes hence it has to be from the Template location.
    Last edited by Sc0tt1e; 10-03-2014 at 09:12 AM.

+ 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. Use Filecopy with PDF document
    By samsmyman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2014, 10:17 AM
  2. Error using VBA FileCopy Function
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-20-2010, 03:03 PM
  3. [SOLVED] filecopy
    By Marvin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2005, 02:05 PM
  4. [SOLVED] FileCopy
    By Andibevan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2005, 10:06 AM
  5. FileCopy
    By Andibevan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-12-2005, 06:06 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