Macro to save active Sheet as new workbook, ask user for location and remove macros from the new workbook

前端 未结 3 1164
时光说笑
时光说笑 2021-01-20 03:50

I have a Workbook with three WorkSheets: Product , Customer, Journal. What I need is a macro assigned to a button within each one of the above Sheets. If the button is click

3条回答
  •  隐瞒了意图╮
    2021-01-20 04:30

    The first one is simple. Use Application.GetSaveAsFilename to allow the user to nominate a path and filename.

    I've used the following from Chip Pearson to strip the VBA out of a copied workbook before, it should do what you are after:

    Sub DeleteAllVBACode()
            Dim VBProj As VBIDE.VBProject
            Dim VBComp As VBIDE.VBComponent
            Dim CodeMod As VBIDE.CodeModule
            
            Set VBProj = myWorkbook.VBProject
            
            For Each VBComp In VBProj.VBComponents
                If VBComp.Type = vbext_ct_Document Then
                    Set CodeMod = VBComp.CodeModule
                    With CodeMod
                        .DeleteLines 1, .CountOfLines
                    End With
                Else
                    VBProj.VBComponents.Remove VBComp
                End If
            Next VBComp
        End Sub

    Sorry, not got time to review your code in detail (leaving work!)

提交回复
热议问题