Results 1 to 5 of 5

Save current active sheet only

Threaded View

Zyphon Save current active sheet only 05-27-2008, 10:44 AM
royUK Try Sub copySht() ... 05-27-2008, 12:15 PM
Zyphon @RoyUK Thanks for your... 05-28-2008, 04:24 AM
royUK Your code is using sh.Name... 05-28-2008, 04:38 AM
Zyphon Perfect! Thank you so much... 05-28-2008, 05:03 AM
  1. #1
    Forum Contributor
    Join Date
    03-30-2007
    Location
    London, UK
    MS-Off Ver
    Microsoft Office 2007
    Posts
    317

    Smile Save current active sheet only

    Hi guys,

    A while ago some kind person on this forum gave me a neat piece of code for save worksheets to seperate files and maintaining the main Filename and apending the file to add the tab name of the worksheet.

    I wondered if I could expand on that. What I need to know is how the code below could be modified so that I could save only the currently active worksheet to a seperate file.

    For example; if my workbook was called Book1.xls and I had the standard sheet names. If say Sheet2 was the active sheet then the code would save that sheet to a seperate Workbook called: Book1 - Sheet2.xls and that this workbook only contained Sheet2 in it.

    Is this possible?

    Thanks in advance.
    Sub SaveAll()
       Dim myWb As Workbook
       
       Set myWb = ActiveWorkbook
       
       myPathWhereToSave = "D:\MS OFFICE\Excel Docs\Temp\"
    
        Application.ScreenUpdating = False
       For Each sh In myWb.Sheets
          sh.Copy
        
          ActiveWorkbook.SaveAs Filename:=myPathWhereToSave & Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & " - " & sh.Name, _
             FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
             ReadOnlyRecommended:=False, CreateBackup:=False
          ActiveWorkbook.Close
       Next
       Application.ScreenUpdating = True
    End Sub
    Last edited by Zyphon; 05-27-2008 at 11:13 AM.
    Best Regards.

    Michael
    -----------------------------------
    Windows Vista, Microsoft Office 2007

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