Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Whole Line in Word

Status
Not open for further replies.

bombdropVB

Programmer
Dec 3, 2002
59
0
0
GB
Hi all im trying to delete a whole line in a document if a element of an array has no value

my code at present just place "46" there due to me using VBKeyDelete, so what do i do to replace the ,marker by completley deleting the line???

Code:
'Loop Through the array placing in the address info     For intLoop = 1 To UBound(vntAddress)         'See if the Array elemnt has a value         If Len(vntAddress(intLoop)) Then             objRange.Find.Execute FindText:="Line " & intLoop & ">", Forward:=True, _                 replacewith:=vntAddress(intLoop), Replace:=wdReplaceAll         Else             objRange.Find.Execute FindText:="Line " & intLoop & ">", Forward:=True, _                 replacewith:=vbKeyDelete, Replace:=wdReplaceAll         End If 'Len(vntAddress(intLoop))     Next 'intloop


thanks
 
Sorry The code looks like so

Code:
    'Loop Through the array placing in the address info
    For intLoop = 1 To UBound(vntAddress)
        'See if the Array elemnt has a value
        If Len(vntAddress(intLoop)) Then
            objRange.Find.Execute FindText:="<Address Line " & intLoop & ">", Forward:=True, _
                replacewith:=vntAddress(intLoop), Replace:=wdReplaceAll
        Else
            objRange.Find.Execute FindText:="<Address Line " & intLoop & ">", Forward:=True, _
                replacewith:=vbKeyDelete, Replace:=wdReplaceAll
        End If 'Len(vntAddress(intLoop))
    Next 'intloop
 
Hi bombdropVB,

If the Selection is in the line you want to delete, you can do ..

Code:
[blue]ActiveDocument.Bookmarks("\Line").Range.Delete[/blue]

But note, this only works with the Selection - not any other Range object.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thanks mate but this sorted my problem out got it from another board but thanks anyway

Code:
        'Loop Through the array placing in the address info
        For intLoop = 1 To UBound(vntAddress)
            'See if the Array elemnt has a value
            If Len(vntAddress(intLoop)) Then
                objRange.Find.Execute FindText:="<Address Line " & intLoop & ">", Forward:=True, _
                    replacewith:=vntAddress(intLoop), Replace:=wdReplaceAll
            Else
                 objRange.Find.Execute FindText:="<Address Line " & intLoop & ">", Forward:=True ', _
                    'replacewith:="", Replace:=wdReplaceAll
                    objRange.Select
                      Application.Selection.Expand wdLine
                      Application.Selection.Delete Unit:=wdCharacter, Count:=1

            End If 'Len(vntAddress(intLoop))
        Next 'intloop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top