Finding the previous section and deleting it

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone show me the VBA syntax to find the previous section from the
current cursor position and deleting it.
 
Dim myrange As Range
Set myrange = Selection.Sections(1).Range
myrange.Start = myrange.Start - 1
myrange.Collapse wdCollapseStart
myrange.Start = myrange.Sections(1).Range.Start
myrange.End = myrange.End + 1
myrange.Delete


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
"better programmer wannabe"
 
Hi Doug, The code works exactly as I described my request, however, I only
wanted to delete the section break, not the whole section. Can you modify the
recommendation to only delete the section break, or at least just go back to
the previous section break. Thanks :-)
 
This will do that.

Dim myrange As Range
Set myrange = Selection.Sections(1).Range
myrange.Start = myrange.Start - 1
myrange.Collapse wdCollapseStart
myrange.End = myrange.Start + 1
myrange.Delete

A wanabee better programmer should be experimenting. I don't know all these
things. What I know is only what's left after I delete all the failures.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
"better programmer wannabe"
 
Thank you Doug - I am duly chastised. However, I experimented for more than
an hour before I made my second post. The one thing I did not do is comment
out that one line of code -:(
It works perfectly now.
 

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

Back
Top