Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

remove manual page breaks before headings and leave the others untouched

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andreas - 03 Mar 2007 07:45 GMT
Hello,

is it possible to tell Word VBA to remove only all manual page breaks
immediately! preceding headings that are formatted with the built-in
heading paragraph style "heading 1" and leave the other page breaks
untouched.

Example

text text text text text text text text text text
------------------------------------------- page break (manual)
Heading 1: The analysis etc.

Should there be a blank paragraph (paragraph mark) between the page
break and heading 1, the page break should not be removed. It should
only be removed if the heading 1 follows directly after.

Kind of a weird request, nevertheless I wonder whether this could be
achieved.

Help is appreciated. Thank you very much in advance.

Regards,

Andreas
Helmut Weber - 03 Mar 2007 08:14 GMT
Hi Andreas,

>Kind of a weird request

not at all.

Like this:

Sub Macro9AA()
Dim rngDcm As Range
Set rngDcm = ActiveDocument.Range
With rngDcm.Find
  .Style = "Heading 1"
  While .Execute
     If rngDcm.Characters.First = Chr(12) Then
        rngDcm.Characters.First = ""
     End If
  Wend
End With
End Sub

There are other ways, of course.

To set a character to "" prevents
autocorrection from executing,
which doesn't matter in this context,
does no harm either,
but prevents endless loops and other complications
in other contexts.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

andreas - 03 Mar 2007 15:37 GMT
> Hi Andreas,
>
[quoted text clipped - 33 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"

Helmut,

thank you very much. As always the macro is working.  Good job.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.