Paragraph selection and Style application anomalies

J

Jeff Wiseman

In a recent thread here (New kind of "char char" bug), John
McGhie stated the following:

----------------------
If a user selects some text and applies a style, Word looks to
see if the paragraph mark is included in the selection. If it
is, Word applies the Paragraph style. If the paragraph mark is
NOT included in the selection, Word creates a new style of type
Character, with the same name as the Paragraph style. It links
them together, and applies the new Character style to the text.
-----------------------

From my experience, If a user places the cursor in a paragraph
but doesn't actually select text, when a paragraph style is
applied, it applies to the whole paragraph even though the
paragraph mark was NOT included. The issue here is that when you
select a non-paragraph type entity (i.e., a selection of text)
and then try to apply a paragraph style to it instead of a
text/character style, it does the opposite to what you would
expect it to do.

This behavior seems to come back to some of those weird
algorithms that Word has for determining what was really selected
in a paragraph base on percentages of how much text in the
paragraph was selected. This seems to be the case in something
I've recently discovered:

If I have a paragraph that has a text string in it that has been
formatted with something like overstrike. If I select the entire
paragraph and apply a paragraph style to it, the style of the
paragraph changes and the overriding character formatting on
those few texts remains. However, if the number of characters in
the paragraph with the special formatting encroaches on around
50% of all characters in the paragraph, the behavior totally
changes--i.e., applying the paragraph style now also blows away
the previously overriding character formatting information that
was there.

This is causing a problem with an activity that I have at work
where we have text that is imported into a Word document and then
the document is formatted with all appropriate styles (this is
automated). Unfortunately, because of this inconsistency, manual
markups in the original text (i.e., bolds, overstrikes,
underscores, italics, etc.) never come through consistantly. If
more than about half of the text in the paragraph has special
formatting, ALL of the formatting in that paragraph will be
thrown away.

Note that I can't remember seeing this in Word 2004 but it seems
to be prevalent in Word 2003.

Does anybody know anything about this inconsistancy or any tricks
to get around it?
 
J

John McGhie

Hi Jeff:

Yes, you are quite correct: I left out the two "edge" cases.

If the selection is an insertion point, or includes the paragraph mark, the
Paragraph style will be applied.

If the selection includes more than 50% of the characters in a paragraph,
the paragraph style will be applied.

If a Paragraph style is applied, the Character formatting applied to less
than 50 per cent of the paragraph will remain.

Word applies styles in an "outside-in" fashion, in the order Document
Defaults, Table, Paragraph, Character, List, then Direct (which is simply an
un-named style).

In Word Mac, we do not have "Document Defaults" yet, and we are not really
using "List" styles.

Hope this helps


In a recent thread here (New kind of "char char" bug), John
McGhie stated the following:

----------------------
If a user selects some text and applies a style, Word looks to
see if the paragraph mark is included in the selection. If it
is, Word applies the Paragraph style. If the paragraph mark is
NOT included in the selection, Word creates a new style of type
Character, with the same name as the Paragraph style. It links
them together, and applies the new Character style to the text.
-----------------------

From my experience, If a user places the cursor in a paragraph
but doesn't actually select text, when a paragraph style is
applied, it applies to the whole paragraph even though the
paragraph mark was NOT included. The issue here is that when you
select a non-paragraph type entity (i.e., a selection of text)
and then try to apply a paragraph style to it instead of a
text/character style, it does the opposite to what you would
expect it to do.

This behavior seems to come back to some of those weird
algorithms that Word has for determining what was really selected
in a paragraph base on percentages of how much text in the
paragraph was selected. This seems to be the case in something
I've recently discovered:

If I have a paragraph that has a text string in it that has been
formatted with something like overstrike. If I select the entire
paragraph and apply a paragraph style to it, the style of the
paragraph changes and the overriding character formatting on
those few texts remains. However, if the number of characters in
the paragraph with the special formatting encroaches on around
50% of all characters in the paragraph, the behavior totally
changes--i.e., applying the paragraph style now also blows away
the previously overriding character formatting information that
was there.

This is causing a problem with an activity that I have at work
where we have text that is imported into a Word document and then
the document is formatted with all appropriate styles (this is
automated). Unfortunately, because of this inconsistency, manual
markups in the original text (i.e., bolds, overstrikes,
underscores, italics, etc.) never come through consistantly. If
more than about half of the text in the paragraph has special
formatting, ALL of the formatting in that paragraph will be
thrown away.

Note that I can't remember seeing this in Word 2004 but it seems
to be prevalent in Word 2003.

Does anybody know anything about this inconsistancy or any tricks
to get around it?

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Microsoft MVP, Word and Word:Mac
Sydney, Australia. mailto:[email protected]
 
J

Jeff Wiseman

John said:
Hi Jeff:

Yes, you are quite correct: I left out the two "edge" cases.

If the selection is an insertion point, or includes the
paragraph mark, the Paragraph style will be applied.

If the selection includes more than 50% of the characters in a
paragraph, the paragraph style will be applied.

If a Paragraph style is applied, the Character formatting
applied to less than 50 per cent of the paragraph will remain.


Word applies styles in an "outside-in" fashion, in the order
Document Defaults, Table, Paragraph, Character, List, then
Direct (which is simply an un-named style).

In Word Mac, we do not have "Document Defaults" yet, and we
are not really using "List" styles.

Hope this helps


Well, it confirms what I've observed. It doesn't solve the
problem of the inconsistent application of the paragraph style to
character formatting with a paragraph.

I have all the special edit selections turned off. I don't like
Word second guessing what I am trying to do because nearly ALL of
the time, it is wrong. There doesn't seem to be any way to turn
this off though.
 
J

Jeff Wiseman

John said:
Hi Jeff:

Yes, you are quite correct: I left out the two "edge" cases.

If the selection is an insertion point, or includes the
paragraph mark, the Paragraph style will be applied.

If the selection includes more than 50% of the characters in a
paragraph, the paragraph style will be applied.

If a Paragraph style is applied, the Character formatting
applied to less than 50 per cent of the paragraph will remain.


Word applies styles in an "outside-in" fashion, in the order
Document Defaults, Table, Paragraph, Character, List, then
Direct (which is simply an un-named style).

In Word Mac, we do not have "Document Defaults" yet, and we
are not really using "List" styles.

Hope this helps


Well, it confirms what I've observed. It doesn't solve the
problem of the inconsistent application of the paragraph style to
character formatting with a paragraph.

I have all the special edit selections turned off. I don't like
Word second guessing what I am trying to do because nearly ALL of
the time, it is wrong. There doesn't seem to be any way to turn
this off though.
 
J

Jeff Wiseman

John said:
Hi Jeff:

Yes, you are quite correct: I left out the two "edge" cases.

If the selection is an insertion point, or includes the
paragraph mark, the Paragraph style will be applied.

If the selection includes more than 50% of the characters in a
paragraph, the paragraph style will be applied.

If a Paragraph style is applied, the Character formatting
applied to less than 50 per cent of the paragraph will remain.


Word applies styles in an "outside-in" fashion, in the order
Document Defaults, Table, Paragraph, Character, List, then
Direct (which is simply an un-named style).

In Word Mac, we do not have "Document Defaults" yet, and we
are not really using "List" styles.

Hope this helps


Well, it confirms what I've observed. It doesn't solve the
problem of the inconsistent application of the paragraph style to
character formatting with a paragraph.

I have all the special edit selections turned off. I don't like
Word second guessing what I am trying to do because nearly ALL of
the time, it is wrong. There doesn't seem to be any way to turn
this off though.
 
J

Jeff Wiseman

John said:
Hi Jeff:

Yes, you are quite correct: I left out the two "edge" cases.

If the selection is an insertion point, or includes the
paragraph mark, the Paragraph style will be applied.

If the selection includes more than 50% of the characters in a
paragraph, the paragraph style will be applied.

If a Paragraph style is applied, the Character formatting
applied to less than 50 per cent of the paragraph will remain.


Word applies styles in an "outside-in" fashion, in the order
Document Defaults, Table, Paragraph, Character, List, then
Direct (which is simply an un-named style).

In Word Mac, we do not have "Document Defaults" yet, and we
are not really using "List" styles.

Hope this helps


Well, it confirms what I've observed. It doesn't solve the
problem of the inconsistent application of the paragraph style to
character formatting with a paragraph.

I have all the special edit selections turned off. I don't like
Word second guessing what I am trying to do because nearly ALL of
the time, it is wrong. There doesn't seem to be any way to turn
this off though.
 
L

Larry

Jeff, I've got a macro that will wrap everything that's italic in the
document in a <i></i> tag pair, everything that's bold in <b></b>,
etc. That's how I protect the local formatting. I've got another one
that will undo that process. Would these macros help? They work even
down to character-by-character.

---larry
 
J

Jeff Wiseman

Larry said:
Jeff, I've got a macro that will wrap everything that's italic in the
document in a <i></i> tag pair, everything that's bold in <b></b>,
etc. That's how I protect the local formatting. I've got another one
that will undo that process. Would these macros help? They work even
down to character-by-character.

---larry


Hi Larry!

Thanks for offering but I suspect that I wouldn't be able to use
it. The source of the text is not coming from Word (it's in DOORS).

Funny thing about it is that it will export body text just fine,
it only starts choking on table cells. My guess is that for
normal body text it actually creates the paragraph object with
the appropriate style and THEN spools in the text with its local
formatting. I think that when the export does table cells, it
reverses this (i.e., applying the assigned style after the text
output) which results in half-time-it-works-half-time-it-doesn't
behavior.

I think that what I need to do is contact Telelogic (the
developers of DOORS) and inquire about the workings of their
export mechanism.
 
J

Jeff Wiseman

Ooooookay, so when my browser says my reply was not sent due to
some illegal address, it lied.

Three times.

(It seems that it didn't like the Australian address in the first
3 attempts :)
 
C

Clive Huggan

Ooh yes, Larry! -- that would be valuable for another context I have been
mulling over.

Just post it here, please.

Thank you for offering this.

Cheers,

Clive Huggan
Canberra, Australia
(My time zone is 5-11 hours different from the Americas and Europe, so my
follow-on responses to those regions can be delayed)
====================================================
 
L

Larry

Ooh yes, Larry! -- that would be valuable for another context I have been
mulling over.

Just post it here, please.

Okay, Clive. You asked for it. It's not the prettiest code but it gets
the job done. In looking at it I realise that I haven't bothered with
smallcaps or allcaps -- you could add those easily enough. Also, at
the comment "Make stuff look bold, italic, etc. once again", you may
not want to do that; that is, you might want to just leave off the
character attributes of text once it's been tagged. Finally, it's set
to operate on the whole document; again, it's an easy adjustment to
make it work on the current selection or range.

~~~~~~~~~~~~~~~~~~~~~~~~~~~ L O N G ~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub TagEmphasisedText()
'
' Turn off change-tracking
ActiveDocument.AcceptAllRevisions
With ActiveDocument
.TrackRevisions = False
.PrintRevisions = False
.ShowRevisions = False
End With

Selection.HomeKey Unit:=wdStory

' Remove any formatting from tab characters
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Superscript = False
.Subscript = False
End With
With Selection.Find
.text = "^t"
.Replacement.text = "^t"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Clean up XML-invalid characters and markers

' Remove white-space at end of paragraph.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.text = ""
.Replacement.text = "^&"
.Replacement.Font.Bold = False
.Replacement.Font.Italic = False
.Replacement.Font.Underline = wdUnderlineNone
.Replacement.Font.Superscript = False
.Replacement.Font.Subscript = False
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Font.Name = "Symbol"
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.text = "[ ^t]@^13"
.Replacement.text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = " @^13"
.Replacement.text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With

' Pre-prep baseline shifts masquerading as subscripts and
superscripts

Selection.Find.ClearFormatting
Selection.Find.Font.Position = -3
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Superscript = False
.Subscript = True
End With
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 Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Font.Position = 3
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Superscript = True
.Subscript = False
End With
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 Replace:=wdReplaceAll

' Clean out any existing <b>, <i>, etc.

Selection.HomeKey Unit:=wdStory

With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<b\>(*)\</b\>"
.Replacement.text = "\1"
.Replacement.Font.Bold = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<i\>(*)\</i\>"
.Replacement.text = "\1"
.Replacement.Font.Italic = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<u\>(*)\</u\>"
.Replacement.text = "\1"
.Replacement.Font.Underline = wdUnderlineSingle
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<s\>(*)\</s\>"
.Replacement.text = "\1"
.Replacement.Font.Superscript = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<sup\>(*)\</sup\>"
.Replacement.text = "\1"
.Replacement.Font.Superscript = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<sub\>(*)\</sub\>"
.Replacement.text = "\1"
.Replacement.Font.Subscript = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Clear Word attributes on all tags

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<[!>]@\>"
.Replacement.text = "^&"
.Replacement.Font.Bold = False
.Replacement.Font.Italic = False
.Replacement.Font.StrikeThrough = False
.Replacement.Font.DoubleStrikeThrough = False
.Replacement.Font.Underline = wdUnderlineNone
.Replacement.Font.Outline = False
.Replacement.Font.Shadow = False
.Replacement.Font.Hidden = False
.Replacement.Font.SmallCaps = False
.Replacement.Font.AllCaps = False
.Replacement.Font.Superscript = False
.Replacement.Font.Subscript = False
.Replacement.Font.Position = 0
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Apply tags based on attributes

' Set up general search attributes
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With

' Bold

' Insert new tags
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "[!^13\<\>]"
.Replacement.text = "‹b›^&‹/b›"
.Replacement.Font.Bold = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Remove extra tags
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/b›‹b›"
.Replacement.text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/b›[^13^t^s^l ]@‹b›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹b›[^13^t^s^l ]@‹/b›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Italic

' Insert new tags
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "[!^13\<\>]"
.Replacement.text = "‹i›^&‹/i›"
.Replacement.Font.Italic = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Remove extra tags
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/i›‹i›"
.Replacement.text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/i›[^13^t^s^l ]@‹i›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹i›[^13^t^s^l ]@‹/i›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Superscript

' Insert new tags
Selection.Find.ClearFormatting
Selection.Find.Font.Superscript = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "[!^13\<\>]"
.Replacement.text = "‹sup›^&‹/sup›"
.Replacement.Font.Superscript = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Remove extra tags
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/sup›‹sup›"
.Replacement.text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/sup›[^13^t^s^l ]@‹sup›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹sup›[^13^t^s^l ]@‹/sup›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Subscript

' Insert new tags
Selection.Find.ClearFormatting
Selection.Find.Font.Subscript = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "[!^13\<\>]"
.Replacement.text = "‹sub›^&‹/sub›"
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Remove extra tags
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/sub›‹sub›"
.Replacement.text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/sub›[^13^t^s^l ]@‹sub›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹sub›[^13^t^s^l ]@‹/sub›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Underscore

' Insert new tags
Selection.Find.ClearFormatting
Selection.Find.Font.Underline = wdUnderlineSingle
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "[!^13\<\>]"
.Replacement.text = "‹u›^&‹/u›"
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Remove extra tags
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/u›‹u›"
.Replacement.text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/u›[^13^t^s^l ]@‹u›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹u›[^13^t^s^l ]@‹/u›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Strikethrough

' With Selection.Find.Replacement.Font
' .StrikeThrough = True
' .DoubleStrikeThrough = False
' End With

' Insert new tags
Selection.Find.ClearFormatting
Selection.Find.Font.StrikeThrough = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "[!^13\<\>]"
.Replacement.text = "‹s›^&‹/s›"
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Remove extra tags
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/s›‹s›"
.Replacement.text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹/s›[^13^t^s^l ]@‹s›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹s›[^13^t^s^l ]@‹/s›"
.Replacement.text = " "
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Make stuff look bold, italic, etc. once again.
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "‹"
.Replacement.text = "<"
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "›"
.Replacement.text = ">"
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.MatchWildcards = True
End With

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<b\>*\</b\>"
.Replacement.text = "^&"
.Replacement.Font.Bold = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<i\>*\</i\>"
.Replacement.text = "^&"
.Replacement.Font.Italic = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<u\>*\</u\>"
.Replacement.text = "^&"
.Replacement.Font.Underline = wdUnderlineSingle
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<s\>*\</s\>"
.Replacement.text = "^&"
.Replacement.Font.StrikeThrough = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<sup\>*\</sup\>"
.Replacement.text = "^&"
.Replacement.Font.Superscript = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<sub\>*\</sub\>"
.Replacement.text = "^&"
.Replacement.Font.Subscript = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' Restore search attributes
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With

MsgBox "Converted character attributes to XML tags." & vbLf &
"Converted non-XML index markers to XML format.", , "Finished
TagEmphasizedText!"
dbug:
End Sub


Sub UntagEmphasisedText()
'''''''''''''''''''''
Dim theFile As String
Dim myDoc As Document
Dim theName As String
Dim theExtH As String
Dim theExtD As String
Dim thePath As String
Dim myCode As String
Dim theRandom As Long
Dim theSynchFile As String
Dim theSynch As String
''''''''''''''''''''''
Selection.HomeKey Unit:=wdStory

With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<b\>(*)\</b\>"
.Replacement.text = "\1"
.Replacement.Font.Bold = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<i\>(*)\</i\>"
.Replacement.text = "\1"
.Replacement.Font.Italic = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<u\>(*)\</u\>"
.Replacement.text = "\1"
.Replacement.Font.Underline = wdUnderlineSingle
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<s\>(*)\</s\>"
.Replacement.text = "\1"
.Replacement.Font.StrikeThrough = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<sup\>(*)\</sup\>"
.Replacement.text = "\1"
.Replacement.Font.Superscript = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "\<sub\>(*)\</sub\>"
.Replacement.text = "\1"
.Replacement.Font.Subscript = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

'On Error Resume Next


bye:
MsgBox "Reverted to local formatting.", , "Finished
UntagEmphasisedText!"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top