Results 1 to 6 of 6
  1. #1
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    This started off on the Word b (Reset Word Styles)

    This started off on the Word board as Styles from a template (W97, WinNT4) but it seemed like time to move it across here.

    After much thinking and playing I think I now have a working version of the Macro to reset formats in Word back to the default for the style. The tricky bit was coping with character styles, some of which were in paragraphs that are being reset and others may be in paragraphs that are otherwise not being changed.

    This was originally going to be a quick piece of code - but it took hours to cope with all the subtleties. I think it is working OK now, but would be grateful for any testing that you can do.

    I have changed the name of the Macro, and the Form to "Reset Manual Formatting", since this describes what it does better.

    StuartR

    edited to add the attachment
    edited a second time to add a couple of bug fixes
    edited a third time - I'm enjoying talking to myself. Another bug fix, this one was based on my misunderstanding of the word Find object. When I was searching for character styles in a paragraph I assumed that para.Range.Find would only find stuff in that paragraph. I know better now.
    Attached Files Attached Files

  2. #2
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: This started off on the Word b (Reset Word Styles)

    Hi Stuart,

    Sorry it took so long; it looks great as far as I can see.

    The only comments are really rather matters of personal preference:

    1) I prefer to write such macros to run on the Selection:
    <pre> For Each paraNext In Selection.Paragraphs</pre>

    2) Perhaps hide the dialog and display an hourglass while the macro runs?
    <pre> System.Cursor = wdCursorWait
    Me.Hide
    Application.ScreenRefresh
    Application.ScreenUpdating = False</pre>

    3) The dialog displays the "attached template". This seems a bit misleading, because the styles are those of the document, and not necessarily of the attached template.

    I haven't been quite able to figure out how your code works; you use some stuff that's new to me.

    Still haven't found the time to throw the bugs out of my old code.
    I did hope that handling as much as possible with find/replace should speed up the code; but your working code is highly preferable to one that doesn't! <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: This started off on the Word b (Reset Word Styles)

    > For Each paraNext In Selection.Paragraphs
    I think this is probably a good idea. What would this do if the selection is just an insertion point? Would it default to the whole document or the current paragraph?

    > System.Cursor = wdCursorWait
    I didn't know this one. That's a good idea. Do I need to set it back later or is this one of those things that gets tidied up automatically behind you?

    > Me.Hide
    For some reason I never thought of hiding the Userform whilst the code was running, I'll certainly do that

    > Application.ScreenRefresh
    I'm happy to do this too.

    Which bit didn't you follow. The basic flow is...

    <pre>Find all document ranges with Character Styles and remember the Range, Font, Style etc
    For each paragraph
    If this paragraph is one of the styles we selected
    Reset all Paragraph attributes that we have been asked to
    Reset all Font attributes that we have been asked to
    End If
    For each character style range that is in the current paragraph
    If EITHER we have just reset the paragraph OR this is a Character style we want to reset
    Reapply the character style to the Range
    Reapply the original settings for any Font characteristics we weren't meant to be changing
    End If
    Next Character style range
    Next paragraph
    </pre>


    StuartR

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: This started off on the Word b (Reset Word Styles)

    > Would it default to the whole document or the current paragraph?

    I guess a user would expect the macro to run on the whole document (or even all StoryRanges) then?

    The reason I suggested it: Imagine you paste a few lines from another document, then you wouldn't have to clean up the whole doc (which might take a long time).


    > Which bit didn't you follow.

    The first line of your pseudocode. But don't try to explain it (that would spoil the fun <img src=/S/grin.gif border=0 alt=grin width=15 height=15>); I'll have another look when I find the time!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: This started off on the Word b (Reset Word Styles)

    I included all your suggested changes. I included an Apply To box that defaults to...
    If there is no selection then "Whole Document"
    If selection is more than one paragraph then "Selected Paragraphs"
    Otherwise "Current Paragraph"

    The system.cursor doesn't seem to do anything. I tried it in a document with complex manual formatting that took 40 seconds to process, as well as in the de######. Can't see anything wrong with it.

    I also added quite a few more comments to help clarify what's going on.

    StuartR

    edited to replace the attachment because I found yet another bug. If a character range extended over multiple paragraphs then I was resetting the beginning of it when processing later paragraphs, leading to resetting the wrong characteristics sometimes. The code has now changed so that the EditFind for character styles is done once for each paragraph.
    Attached Files Attached Files

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: This started off on the Word b (Reset Word Styles)

    Since Klaus asked so nicely...

    This now handles all story ranges if you select apply to whole document.

    I also included a running total of paragraphs processed in the Statusbar, because it can be slow on a large document.

    StuartR
    Attached Files Attached Files

Posting Permissions

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