Save only one worksheet of a workbook VBA

midnight76

New Member
Joined
Nov 15, 2020
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi guys,

I'm working with these codes and I want to save as just a single worksheet but the whole workbook is saved instead.

Moreover, I wanna create a shortcut of this new Excel workbook (which containing just 1 worksheet) in another folder and It would take a pop-up that asks in which year to create the shorcut. Can someone please give it a look?

Really appreciated!!!

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 1 Then
        Target.Copy Worksheets("TechnicalSheet").Cells(1, 2)
                  
        Set A = ThisWorkbook.Sheets("TechnicalSheet")
        Set B = Workbooks.Add
        Set C = ThisWorkbook.Sheets("Rules")
        
        A.Activate
        A.Copy
        With ActiveSheet.UsedRange
        .Value = .Value
        End With
        B.Activate
        B.Sheets(1).Cells.PasteSpecial Paste:=xlPasteValues
        B.Sheets(1).Cells.PasteSpecial Paste:=xlPasteFormats
        B.Sheets(1).Name = "NEW"
        
        Firststep = B.Sheets("NEW").Range("H1").End(xlDown).Row
        Laststep = B.Sheets("NEW").Range("H10000").End(xlUp).Row
        
        For i = Firststep To Laststep
            If B.Sheets("NEW").Cells(i, 8).Value = "Not available" Then
               B.Sheets("NEW").Range("H" & i).EntireRow.Hidden = True
            End If
        Next i
        
        C.Activate
        C.Cells.Copy
        B.Sheets(2).Cells.PasteSpecial Paste:=xlPasteValues
        B.Sheets(2).Cells.PasteSpecial Paste:=xlPasteFormats
        B.Sheets(2).Name = "Rules"
    
        File = Application.GetSaveAsFilename(InitialFileName:="NEW -" & Target.Value & ".xlsm", FileFilter:= _
               "Excel Files Macro Enabled" & "Workbook (*.xlsm), *xlsm")
         If File = False Then
            Exit Sub
         End If
        Application.DisplayAlerts = False
        ActiveWorkSheet.SaveAs Filename:=File, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
    End If

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Oh, I've just deleted an extra part (which I removed from the last version..) and only the worksheet required is saved.
Need some help with the shortcut creation part.

Thank you!!!
 
Upvote 0

Forum statistics

Threads
1,215,424
Messages
6,124,817
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top