I have an analysis workbook with multiple tabs that is too large to share with a broader audience and so I have created a macro which summarizes the results of the analysis on a new tab, copies that tab to a new workbook and then saves that workbook under a new name. As a part of the macro I create two buttons....the first button clears filters from the worksheet and the second button selects a defined range and prompts the sort command.

My problems is that when the sheet copies to a new workbook it retains the buttons but loses the connection to the underlying macros that were assigned to them....is there a way to either 1) export the module/macro with the sheet as it is copied to a new workbook or 2) to have the code write the macro in the new workbook so that it can be assigned to the buttons. Any help with this question would be greatly appreciated.

Here is a copy of the code I use to reset filters and prompt the sort command.

  
Sub refreshFilters()
With Worksheets("OTB")
     If .AutoFilterMode Then
       If .FilterMode Then
         ActiveSheet.ShowAllData
       End If
     End If
    End With 
End Sub
Sub Sort()
Dim sweepTab As String
Dim sortRange As String

    Worksheets("Macro Inputs").Calculate

    sweepTab = Worksheets("OTB")
    sortRange = Worksheets("OTB").Range("A6:BK14000")

    Worksheets(sweepTab).Unprotect "core"
    
    With Worksheets(sweepTab)
     If .AutoFilterMode Then
       If .FilterMode Then
         ActiveSheet.ShowAllData
       End If
     End If
    End With
    
    ActiveSheet.Range(sortRange).Select

    
    Application.CommandBars.ExecuteMso ("SortCustomExcel")

End Sub