Question : Delete whole line in word doc

Experts -

Using VB.Net I'm trying to delete a whole line in a word doc. I found the following function, but I can't get it to work! Any help would be appreciated. I would like the function to simply pass in the word doc that I'm already accessing, for example something like:

Private sub DeleteLine(ByRef doc As Object)

Anyways, below is the function I found, but I can't get it to work. I would like to delete the whole line where the word "Filed:" appears.

Sub RemoveWelshLines()
Selection.HomeKey Unit:=wdStory
Selection.Find.Text = "Filed:"
Do While Selection.Find.Execute(FindText:="Filed:", Forward:=True, _
            Format:=True) = True
    With Selection
            .Expand Unit:=wdLine
            .Delete
    End With
Loop

TIA!

Answer : Delete whole line in word doc

Do you get any errors, or does it not find anything?

I don't think that the unqualified Selection object helps.

See if this works (I don't have .Net to run a full test)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Sub RemoveWelshLines(doc As Object)
Dim wdApp As Object 'Word.Application
'Dim doc As Word.Document
'Set wdApp = doc.Application
wdApp = doc.Application
doc.Range.Select
wdApp.Selection.Find.Text = "Filed:"
Do While wdApp.Selection.Find.Execute(FindText:="Filed:", Forward:=True, _
            Format:=True) = True
    With wdApp.Selection
            .Expand Unit:=wdLine
            .Delete
    End With
Loop
End Sub
Random Solutions  
 
programming4us programming4us