Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy one workbook to another workbook (Excel 2000/SR1)

    How does one copy one workbook to another via VBA code. We wnat to be able to open an existing xls file and it it turn opens a new workbook and copies it's contents to the new workbook and save it as a new xls. Is there example code?

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Copy one workbook to another workbook (Excel 2000/SR1)

    Why don't you just use:

    ActiveWorkbook.SaveAs Filename:="newname.xls"

    Steve

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

    Re: Copy one workbook to another workbook (Excel 2000/SR1)

    You can use the SaveCopyAs method, which saves a copy of an existing open workbook, but leaves the existing workbook with it's original name in memory.

    The following code should do teh job :

    ActiveWorkbook.SaveCopyAs "Copy of " & ActiveWorkbook.FullName

    or if not the active workbook,

    Workbooks("WorkbookName.xls").SaveCopyAs Workbooks("WorkbookName.xls").Path & "Copy of WorkbookName.xls"


    You can of course use any name you like that does not conflict with an existing file. Also note that the above examples save the copy to the same folder that holds the original file. This does not need to be the case and you can specify whatever path you wish.

    Andrew C

Posting Permissions

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