PDA

View Full Version : Delete single procedures



XL-Dennis
05-25-2004, 04:26 PM
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)


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


Is the above an acceptable way when working in Word?

TIA,
Dennis

fumei
06-01-2004, 01:44 PM
Yes. It works well.

As you note, it requires that VBA Extensibility be referenced, other wise this will not work.