Hello,
I had a quick question, more related to VBA, as opposed to VB.
Right now in my document I have a command button that saves the document when you click the command button. What I want to do, is I have a script that removes VBA from the Word document after the command button is clicked:
The process would be > User clicks command button to save document > after document is saved > another script executes right away and delete's all VBA in the VBE.. Right now I have a script that saves the document, and another one that will remove the vba - but Im just a little hazy on how I would combine the two scripts - any help would be appreciated, if possible.
Code for Command button:
Code:Private Sub CommandButton1_Click() Dim i As Long, l As Long Dim Today, FolderName$, DateValue$, NameofFile$, FullFileName$ FolderName$ = "X:\Weekly Meetings\" DateValue$ = Format(Now, "yyyy-mm-dd") NameofFile$ = "- Core Agenda" FullFileName$ = FolderName$ + DateValue$ + " " + NameofFile$ ActiveDocument.SaveAs FileName:=FullFileName$, FileFormat:=wdFormatDocument End Sub
Code for Removal of VBA
Code:Sub If objDocument Is Nothing Then Exit Sub i = 0 On Error Resume Next i = objDocument.VBProject.VBComponents.Count On Error GoTo 0 If i < 1 Then ' no VBComponents or protected VBProject MsgBox "The VBProject in " & objDocument.Name & _ " is protected or has no components!", _ vbInformation, "Remove All Macros" Exit Sub End If With objDocument.VBProject For i = .VBComponents.Count To 1 Step -1 On Error Resume Next .VBComponents.Remove .VBComponents(i) ' delete the component On Error GoTo 0 Next i End With With objDocument.VBProject For i = .VBComponents.Count To 1 Step -1 l = 1 On Error Resume Next l = .VBComponents(i).CodeModule.CountOfLines .VBComponents(i).CodeModule.DeleteLines 1, l ' clear lines On Error GoTo 0 Next i End With End Sub




Reply With Quote