Consulting

Results 1 to 3 of 3

Thread: Create copy of WB

  1. #1

    Create copy of WB

    Hello,

    Guess it easy, but I couldn't find it. How could I create a copy of active wb, usual way with SaveCopyAs and then open is not very effective for me, as I work with big files, so the saving took a lot of time. Thanks in advance.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    In this method, the 2nd input parameter can also be just a different path. Note that FileCopy will error so I used an FSO method. You will need to save the current file first if you want any changes saved.

    Sub Test_CopyActiveWorkbook()
      CopyActiveWorkbook ThisWorkbook, "c:\temp\" & ThisWorkbook.Name
    End Sub
    
    Sub CopyActiveWorkbook(aWB As Workbook, theFullPathName As String)
      'FileCopy aWB.FullName, theFullPathName 'Errors
      CopyFile aWB.FullName, theFullPathName
    End Sub
    
    Sub CopyFile(filespec, Destination)
        Dim fs, f, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        fs.CopyFile filespec, Destination
    End Sub

  3. #3
    Hi Kenneth, thanks this way I found out. It works quite well
    With NewBook
            .SaveAs Filename:="C:\" & "copy") & ".xls"
            Workbooks("file.xls").Activate
            ThisWorkbook.Sheets.Copy After:=Workbooks("copy".xls").Worksheets(Workbooks("copy.xls").Worksheets.Count)
        End With

Posting Permissions

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