Reply
 
Thread Tools Display Modes
  #1   Report Post  
better programmer wannabe
 
Posts: n/a
Default Finding the previous section and deleting it

Can someone show me the VBA syntax to find the previous section from the
current cursor position and deleting it.
  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

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"
wrote in message
...
Can someone show me the VBA syntax to find the previous section from the
current cursor position and deleting it.



  #3   Report Post  
better programmer wannabe
 
Posts: n/a
Default

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 :-)

"Doug Robbins" wrote:

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"
wrote in message
...
Can someone show me the VBA syntax to find the previous section from the
current cursor position and deleting it.




  #4   Report Post  
Doug Robbins
 
Posts: n/a
Default

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"
wrote in message
...
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 :-)

"Doug Robbins" wrote:

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"
wrote in message
...
Can someone show me the VBA syntax to find the previous section from
the
current cursor position and deleting it.






  #5   Report Post  
better programmer wannabe
 
Posts: n/a
Default

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.

"Doug Robbins" wrote:

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"
wrote in message
...
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 :-)

"Doug Robbins" wrote:

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"
wrote in message
...
Can someone show me the VBA syntax to find the previous section from
the
current cursor position and deleting it.






Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
section breaks, orientation and margins A. Siddiqi Microsoft Word Help 6 April 29th 06 12:17 AM
Getting different footers Joe McGuire Microsoft Word Help 4 June 20th 05 05:50 PM
Cannot delete a Section Break JMMerrick Microsoft Word Help 1 March 14th 05 11:40 PM
deleting section breaks donna Microsoft Word Help 1 February 17th 05 05:49 PM
allow users to select section formatting when deleting section bre GabweY Page Layout 0 February 17th 05 05:35 PM


All times are GMT +1. The time now is 11:53 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"