+ Reply to Thread
Results 1 to 5 of 5

Copy a sheet and save as new file, without opening the file

Hybrid View

  1. #1
    Registered User
    Join Date
    09-09-2009
    Location
    Chatham, ON
    MS-Off Ver
    Excel 2003
    Posts
    22

    Copy a sheet and save as new file, without opening the file

    is it possible to copy one sheet in a workbook onto a new workbook then save it but not open the file?
    I know i can open, save then close all in vba, but is there a way to do it in the background?

    my current code looks like this

    BidFile = Workbooks("Bid Sheet Creator").Sheets("Bid Sheet").Rows(3).Columns(2)
    Application.CutCopyMode = False
    Sheets("Bid Sheet").Copy
    ActiveSheet.Name = BidFile
    So i am copying my "Bid Sheet" to a new file and giving it a name. I have code below this saving the file then closing it but i am wondering if there is a way to change my above code to do it all in the background?

    Thanks in advance

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

    Re: Copy a sheet and save as new file, without opening the file

    In VBA you can create a new, hidden instance of Excel, open the file, copy the sheet, save the file, and quit the hidden instance.

    I know of no way to copy a single sheet to a new workbook without opening the workbook.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-09-2009
    Location
    Chatham, ON
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Copy a sheet and save as new file, without opening the file

    How would i go about opening the hidden excel, sorry i am all self taught in this stuff and haven't come across this before.

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

    Re: Copy a sheet and save as new file, without opening the file

    Something like this:
    Sub x()
        With New Excel.Application
            .Open "C:\myPath\MyWorkbook.xls"
            .Worksheets("Bid Sheet").Copy
            With .ActiveSheet
                .Name = .Range("B3").Value
            End With
            .ActiveWorkbook.SaveAs "C:\myOtherPath\someName.xls"
            .ActiveWorkbook.Close                       ' the new workbook
            .ActiveWorkbook.Close SaveChanges:=False    ' the old workbook
            .Quit
        End With
    End Sub

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

    Re: Copy a sheet and save as new file, without opening the file

    Or, more simply,
    Sub x()
        With Application
            .ScreenUpdating = False
            .Workbooks.Open "C:\myPath\MyWorkbook.xls"
            .Worksheets("Bid Sheet").Copy
            With .ActiveSheet
                .Name = .Range("B3").Value
            End With
            .ActiveWorkbook.SaveAs "C:\myOtherPath\someName.xls"
            .ActiveWorkbook.Close                       ' the new workbook
            .ActiveWorkbook.Close SaveChanges:=False    ' the old workbook
            .ScreenUpdating = True
        End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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