Consulting

Results 1 to 5 of 5

Thread: Create Copies of Workbook

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location

    Create Copies of Workbook

    I want to do the following:
    -Open Workbook A
    -Create 2 copies of Workbook A (I'll name them Workbook B & C).
    -Modify Workbooks B & C slightly
    -Save all 3 workbooks.

    I'm running into trouble creating copies of workbook A. If I use the WB.SaveAs method, I can create Workbook B, but Workbook A is now closed.

    Is there a way to create a copy of a workbook without losing the original workbook?

    Thanks,

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Maybe savecopyas will work better. Try this, it seems to do what you require.

    [VBA]
    Sub savecopyas()
    ActiveWorkbook.savecopyas "C:\TEMP\XXXX.XLS"
    ActiveWorkbook.savecopyas "C:\TEMP\ooo.XLS"
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location
    Thanks Lucas. SaveCopyAs creates a copy but that copy is not an open workbook. So if want to modify the workbook (which I do), I'm forced to open it. Seems like a waste. Seems like there should be a way to make a copy of a WB and have that WB stay open.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    If it's important you can open them after creating them:
    [VBA]
    Sub savecopyas()
    ActiveWorkbook.savecopyas "C:\TEMP\XXXX.XLS"
    ActiveWorkbook.savecopyas "C:\TEMP\ooo.XLS"
    ChDir "C:\Temp"
    Workbooks.Open Filename:="C:\Temp\XXXX.XLS"
    Workbooks.Open Filename:="C:\Temp\ooo.XLS"
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location
    Thanks Lucas. I take it there is no way to copy a workbook and leave it open then? When I work remotely, it can take up to 20 seconds or so to open a workbook. Some of my programs open 100s of workbooks. So saving a copy and then re-opening the copy could potentially cost me many minutes of run time. Seems like there should be a more efficient way.

    Anyway, thanks for the helpl

Posting Permissions

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