Delete from Last Line two lines up VBA

E

Enrique Rojas

Hello,

I have one line at the end of a document that I want to delete. I have
been playing with selections and ranges but nothing is erasing it.

the content is like this
----------------------------------------------------
blah blah blah

Finance level #
-------------------------------------------------

I want to erase Finance Level # and leave blah blah blah

PS. I cannot use code with := in it. My ASP server does not accept it.

Thanks in advance.
 
H

Helmut Weber

Hi Enrique,

if you're sure, that there are no linefeed
or other control characters present
and you are talking about lines
not one-line-paragraphs, try this:

Sub Test455678()
With selection
.ExtendMode = false
.EndKey 6 'wdstory
.ExtendMode = True
.HomeKey 5 'wdline
.Delete
.EndKey 6
.ExtendMode = True
.HomeKey 5 'wdline
.Delete
End With
End Sub

As to other solutions:
selection.Bookmarks("\line").Select
does not work in the last line in the doc
if the not extended selection is immediately
before the end-of-doc mark or
if the end-of-doc mark is selected.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top