Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Aug 2002
    Location
    Sierra Madre, California, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Style Separator (Lead emphasis text in TOC) (Word XP)

    Hi guys!

    I'm trying to write some code so that Word XP's new Style Separator works better. It's "supposed" to let you have leading emphasis text that shows up in a table of contents and not the rest of the paragraph. (It's a glorified hidden paragraph mark). The only way it works correctly is on a document that you are "typing" and only if you're using heading styles followed by non-heading styles. And it doesn't work for numbered styles (it hides the number)

    I need to to work on an existing document. I've sort of put together some stuff. I need it to loop through a piece of the code several times but not sure of the best way to do that. Right now it only does the first paragraph.

    I've also written the code for unhiding the number - but it's kinda sloppy.

    The code is as follows and I've attached a sample document with styles and the macro. run it in one of the level one styles and then update the TOC.

    Thanks in advance.

    Selection.HomeKey Unit:=wdStory 'start at the top

    '******************* Part of Code I want to repeat ***************
    <font color=448800> 'find the appropriate paragraphs based on style and execute the following </font color=448800>

    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles(strNumStyle)
    With Selection.Find
    .Text = "." <font color=448800> 'this finds the first sentence also don't want the period in TOC</font color=448800>
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute

    Selection.MoveLeft Unit:=wdCharacter, Count:=1 <font color=448800> 'get to the left of period</font color=448800>

    Selection.TypeParagraph
    Selection.MoveUp Unit:=wdLine, Count:=1
    Selection.EndKey Unit:=wdLine
    Selection.InsertStyleSeparator 'must have Word XP
    Selection.TypeBackspace 'get rid of extra space
    Selection.Style = ActiveDocument.Styles(strNumBodyStyle)

    <font color=448800> '******************* END OF Part of Code I want to repeat ***************</font color=448800>

    <font color=448800> 'more code goes here</font color=448800>

    <font color=448800> 'for some reason the number gets hidden so you need to unhide it</font color=448800>
    <font color=448800> 'any better way to do this?</font color=448800>
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting <font color=448800> 'find the appropriate paragraphs</font color=448800>
    Selection.Find.Style = ActiveDocument.Styles(strNumStyle)
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With

    Selection.Find.Execute

    Selection.HomeKey Unit:=wdLine
    Selection.HomeKey
    Selection.Paragraphs(1).SelectNumber
    With Selection.Font
    .Hidden = False
    End With

    <font color=448800> 'more code</font color=448800>

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Style Separator (Lead emphasis text in TOC) (Word XP)

    Since no-one else has had a go at it yet, I thought I would have an attempt. I didn't have the problem of the number disappearing and was interested in your code to solve that issue.
    <pre>Option Explicit

    Sub StyleSeparatorCustom()
    Dim strNumStyle As String
    Dim iCounter As Integer
    ActiveWindow.ActivePane.View.ShowAll = True 'show hidden marks to make this work?
    'let the user return to their starting point
    ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="one"
    strNumStyle = "LevelOne"
    iCounter = 0
    Do
    With Selection.Find
    .ClearFormatting 'find the appropriate paragraphs
    .Style = ActiveDocument.Styles(strNumStyle)
    .Text = "."
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
    While .Found = True
    With Selection
    .Range.InsertBefore vbCr
    .InsertStyleSeparator 'must have Word XP
    .TypeBackspace
    .Style = ActiveDocument.Styles(strNumStyle & "Body")
    End With
    .Execute
    Wend
    strNumStyle = "LevelTwo"
    iCounter = iCounter + 1
    End With
    Loop Until iCounter = 2

    Selection.GoTo What:=wdGoToBookmark, Name:="one"
    ActiveDocument.Bookmarks("one").Delete
    Exit Sub

    errHandler:
    If Err.Number = 4605 Then
    Selection.MoveRight
    Else: MsgBox "Please record this error number and report to Kris" & _
    Err.Number & " " & Err.Description
    End If
    End Sub</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Lounger
    Join Date
    Aug 2002
    Location
    Sierra Madre, California, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Style Separator (Lead emphasis text in TOC) (Word XP)

    Thanks for taking a look at it. You gave me some ideas. I tried a variation of While...Wend that I found while out-of-town. I am anxious to compare it to your code to see if I can make improvements. I will post the result tomorrow.

    The number doesn't disappear in the document itself, but rather in the generated TOC. The code I had in the body of my post was a snippet of the code in the document I attached. The document also contained a TOC and the code for making the number visible.

    I'll keep you posted. Thanks! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •