View Single Post
  #6  
Old August 13th, 2006, 01:33 PM posted to microsoft.public.word.pagelayout
Jay Freedman
external usenet poster
 
Posts: 9,488
Default How to create style to automatically suppress CR after a Headi

You're welcome.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Sat, 12 Aug 2006 17:18:01 -0700, MarkLTaper
wrote:

Well I didn't want to ask because that would have been greedy. This is
perfect, and I doubt I could have constructed it myself.

Thanks MarkLTaper

"Jay Freedman" wrote:

Hi Mark,

Ask and ye shall receive....

Sub RuninAllHeading4()
Dim SearchRg As Range
Dim HideRg As Range
Set SearchRg = ActiveDocument.Range
With SearchRg.Find
.ClearFormatting
.Text = ""
.Style = wdStyleHeading4
.Format = True
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = False
Do While .Execute
Set HideRg = SearchRg.Duplicate
With HideRg
.Collapse wdCollapseEnd
.MoveStartWhile cset:=Chr(13), Count:=wdBackward
.Font.Hidden = True
End With

With SearchRg
.Collapse wdCollapseEnd
.MoveEnd unit:=wdCharacter, Count:=1
.Select
If (.Text " ") And (.Text Chr$(9)) Then
.InsertBefore " "
End If
.Collapse wdCollapseEnd
End With
Loop
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Sat, 12 Aug 2006 15:57:01 -0700, MarkLTaper
wrote:

Jay, This is great. I can see that macros open up a vast flexibility. I
will work on implimenting this macro. However, I am thinking that for my
purposes, a macro that searchs for every level 4 heading goes to its end and
hides the CR would be most effective. Are their subtle enough search
functions in the macro language to make this approach work? If you think so
then I will try to work this out.

Thanks again

"Jay Freedman" wrote:

OK, I see what you're trying to do. It will be possible with a macro
-- more likely, a series of macros -- that do all the formatting. You
can assign each macro to a toolbar button, a shortcut key, or both.

An example macro is shown below. This is specific for the situation
you showed; if you want other heading styles, or other assumptions
about the starting selection, you'd need other macros for those.

This example assumes that you've already typed the text of both the
heading and at least part of the following text, all in the regular
body style in a single paragraph, and that you've selected the part
you want to make into a Heading 4. It doesn't work right if you select
an entire paragraph.

Sub ApplyRunin4()
' the selected text will take Heading 4 style
' with a hidden paragraph mark at the end

If Selection.Type wdSelectionNormal Then
MsgBox "Please select the heading text first."
Exit Sub
End If

If Selection.Start Selection.Paragraphs(1).Range.Start Then
MsgBox "Please select text at the beginning of the paragraph."
Exit Sub
End If

With Selection
.InsertParagraphAfter
.Collapse wdCollapseStart
.Style = ActiveDocument.Styles("Heading 4")
.Paragraphs(1).Range.Select
.Collapse wdCollapseEnd
.MoveStart wdCharacter, -1
.Font.Hidden = True
End With
End Sub

For help with installing the macro and assigning it to a button and/or
shortcut, see these articles:

http://www.gmayor.com/installing_macro.htm
http://www.word.mvps.org/FAQs/Custom...oToToolbar.htm
http://www.word.mvps.org/FAQs/Custom...roToHotkey.htm

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Sat, 12 Aug 2006 12:03:02 -0700, MarkLTaper
wrote:

I am trying to create a heading style so that following text begins on the
same line, but I am baffled. I see no way to suppress the carriage return.
Jay Freedman's response to my previous question showed how to manually
format to create the proper effect on a case by case basis not how to set up
a style.
I use this format frequently so I would like to have it automatic, if
possible.

Thanks MLT

I want:

Heading 4: Following text

not

Heading 4:
Following text