-
Delete single procedures
Hi all :hi:
Below You find the approach I use in Excel "converted" to Word to delete single procedures (it use early binding to Microsoft Visual Basic for Applications Extensibility 5.3)
[vba]
Option Explicit
Sub Delete_Procedure()
Dim wdDoc As Document
Set wdDoc = ActiveDocument
Dim vbaProject As VBIDE.VBProject
Dim vbaModule As VBIDE.VBComponent
Dim vbacdModule As VBIDE.CodeModule
Set vbaProject = wdDoc.VBProject
Set vbaModule = vbaProject.VBComponents("ThisDocument")
Set vbacdModule = vbaModule.CodeModule
With vbacdModule
.DeleteLines .ProcStartLine("Test", 0), .ProcCountLines("Test", 0)
End With
Set vbacdModule = Nothing
Set vbaModule = Nothing
Set vbaProject = Nothing
End Sub
[/vba]
Is the above an acceptable way when working in Word?
TIA,
Dennis
-
Yes. It works well.
As you note, it requires that VBA Extensibility be referenced, other wise this will not work.