Re: Replacing VBA code on Mass by Helmut
Helmut
Fri Dec 05 12:43:09 CST 2003
Hi Mark,
given, opening all the 250 docs is not a problem,
and you have set a reference to the appropriate
Microsoft Visual Basic for Applications Extensibility.
then the routine, to delete the first line that
contains "An Error" line, would look like this.
Sub DeleteLineInMacro()
Dim lLin As Long ' line
Dim i As Integer
VBE.MainWindow.Visible = True 'show editor
With VBE.VBProjects("Normal").VBComponents("ThisModule")
.CodeModule.CodePane.Show ' show code
lLin = .CodeModule.CountOfLines ' all lines
If .CodeModule.Find("An Error", 1, 1, lLin, 1) Then
.CodeModule.DeleteLines (lLin)
exit sub
End If
End If
End With
End Sub
Further is assumed: The line is in the project "normal"
and there in the component "ThisModule".
Is it possible though, to construct a loop over all
components od all modules. But beware, to place the above
routine at the end of whatever component. Otherwise,
it might delete the search string in itself.
A bit tricky, indeed!
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98