Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Copy workbook to another location without opening

This is a discussion on Copy workbook to another location without opening within the Excel Questions forums, part of the Question Forums category; Hello, I am trying to copy a workbook without opening it and save it to a different location/file name (2nd ...

  1. #1
    Board Regular
    Join Date
    Mar 2003
    Posts
    130

    Default Copy workbook to another location without opening

    Hello,
    I am trying to copy a workbook without opening it and save it to a different location/file name (2nd workbook) from a third workbook.
    Anybody got any ideas?
    Thanks,
    leeloo

  2. #2
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202

    Default Re: Copy workbook to another location without opening

    Sub CopyFile()

    FileCopy Source:="C:\Book3.xls", Destination:="C:\VBA Code\Book5.xls"

    End Sub

  3. #3
    Board Regular
    Join Date
    Mar 2003
    Posts
    130

    Default Re: Copy workbook to another location without opening

    Excellent, thank ya!

  4. #4
    Board Regular
    Join Date
    Jan 2012
    Location
    Alabama
    Posts
    589

    Default Re: Copy workbook to another location without opening

    How could this be adjusted to write over the destination file each time but as the same file name.. Thanks

  5. #5
    VoG
    VoG is offline
    MrExcel MVP
    Moderator
    VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,537

    Default Re: Copy workbook to another location without opening

    Try like this

    Code:
    Sub CopyFile()
    On Error Resume Next
    Kill "C:\VBA Code\Book5.xls"
    On Error GoTo 0
    FileCopy Source:="C:\Book3.xls", Destination:="C:\VBA Code\Book5.xls"
    End Sub
    HTH, Peter
    Please test any code on a copy of your workbook.

  6. #6
    Board Regular
    Join Date
    Jan 2012
    Location
    Alabama
    Posts
    589

    Default Re: Copy workbook to another location without opening

    Peter if another user has open book5 when the code is executed will it still replace it even though its open.

  7. #7
    Board Regular
    Join Date
    Jan 2012
    Location
    Alabama
    Posts
    589

    Default Re: Copy workbook to another location without opening

    If i want to use the Active Workbook could this work ?
    On Error Resume Next
    Kill "H:\All\Material Prep Archive\(Public)Archive .xls"
    On Error GoTo 0
    FileCopy Source:="Activeworkbook:="H:\All\Material Prep Archive\(Public)Archive .xls"

  8. #8
    VoG
    VoG is offline
    MrExcel MVP
    Moderator
    VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,537

    Default Re: Copy workbook to another location without opening

    Quote Originally Posted by bamaisgreat View Post
    Peter if another user has open book5 when the code is executed will it still replace it even though its open.
    I think that would fail - you'd have to test to be sure.
    HTH, Peter
    Please test any code on a copy of your workbook.

  9. #9
    VoG
    VoG is offline
    MrExcel MVP
    Moderator
    VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,537

    Default Re: Copy workbook to another location without opening

    Quote Originally Posted by bamaisgreat View Post
    If i want to use the Active Workbook could this work ?
    I think that you would need

    Code:
    On Error Resume Next
    Kill "H:\All\Material Prep Archive\(Public)Archive .xls"
    On Error GoTo 0
    FileCopy Source:=ActiveWorkbook.FullName, Destination:="H:\All\Material Prep Archive\(Public)Archive .xls"
    HTH, Peter
    Please test any code on a copy of your workbook.

  10. #10
    Board Regular
    Join Date
    Jan 2012
    Location
    Alabama
    Posts
    589

    Default Re: Copy workbook to another location without opening

    If i add the On Error Resume Next above the file copy will it skip the FileCopy if the destination (PublicArchive.xls) is open?
    Like Below

    On Error Resume Next
    Kill "H:\All\Material Prep Archive\(Public)Archive .xls"
    On Error GoTo 0
    On Error Resume Next
    FileCopy Source:=ActiveWorkbook.FullName, Destination:="H:\All\Material Prep Archive\(Public)Archive .xls"

Page 1 of 2 12 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com