Saving a copy of just one worksheet + remove buttons

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
616
Hi,
I have a workbook which I use savecopyas often and with a file size of around 6MB, it's using up space fast.

Source workbook contains many sheets/macros/formulas

And I only need to save 1 sheet (Main) to a new workbook and remove buttons + turn sheet to values if possible. Note the sheet is protected but no password

What is the best way to do this?

Thanks
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,512
Try:
Code:
Sub SaveMain()
    Application.ScreenUpdating = False
    Dim sh As Shape
    Sheets("Main").Copy
    With ActiveSheet
        .Unprotect
        .UsedRange.Cells.Value = .UsedRange.Cells.Value
        For Each sh In .Shapes
            sh.Delete
        Next sh
        .Protect
        .EnableSelection = xlUnlockedCells
    End With
    With ActiveWorkbook
        .SaveAs Filename:="[COLOR="#FF0000"]C:\Test\[/COLOR]" & [COLOR="#0000FF"]ActiveWorkbook.Name[/COLOR], FileFormat:=51
        .Close False
    End With
    Application.ScreenUpdating = True
End Sub
Change the folder path (in red) and the workbook name (in blue) to suit your needs.
 

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
616
Thanks @mumps

this works (almost perfect)

it currently deletes all buttons, but also deletes the textbox's i have on the sheet which i want to keep
is there any way to skip textboxe's in the loop ?
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,512
Try:
Code:
Sub SaveMain()
    Application.ScreenUpdating = False
    Dim sh As Shape, sh2 As Shape, srcWS As Worksheet, sName As String
    Set srcWS = ThisWorkbook.Sheets("Main")
    With srcWS
        .Unprotect
        .Copy
    End With
    With ActiveSheet
        .Unprotect
        .UsedRange.Cells.Value = .UsedRange.Cells.Value
        For Each sh In srcWS.Shapes
            sName = sh.Name
            sh.Copy
            ActiveSheet.Paste
            Set sh2 = .Shapes(.Shapes.Count)
            sh2.Name = sName
            sh2.Top = sh.Top
            sh2.Left = sh.Left
        Next sh
        For Each sh In .Shapes
            If Left(sh.Name, 7) <> "TextBox" Then
                sh.Delete
            End If
        Next sh
        .Protect
        .EnableSelection = xlUnlockedCells
    End With
    With ActiveWorkbook
        .SaveAs Filename:="C:\Test\" & ActiveWorkbook.Name, FileFormat:=51
        .Close False
    End With
    Application.ScreenUpdating = True
End Sub
 

Forum statistics

Threads
1,081,835
Messages
5,361,600
Members
400,640
Latest member
fruitbros

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top