TechWhirl (TECHWR-L) is a resource for technical writing and technical communications professionals of all experience levels and in all industries to share their experiences and acquire information.
For two decades, technical communicators have turned to TechWhirl to ask and answer questions about the always-changing world of technical communications, such as tools, skills, career paths, methodologies, and emerging industries. The TechWhirl Archives and magazine, created for, by and about technical writers, offer a wealth of knowledge to everyone with an interest in any aspect of technical communications.
Subject:RE: Finding character styles in Word with VBA From:"Mike Feimster" <mike -dot- feimster -at- acstechnologies -dot- com> To:<techwr-l -at- lists -dot- techwr-l -dot- com>, <Robert -dot- Partridge -at- au -dot- unisys -dot- com> Date:Wed, 22 Mar 2006 08:35:54 -0500
Robert,
I'm on digest so I don't know if you've gotten an answer yet.
If you are trying to replace one character style with another, you should be
able to use the same code. Just remove the ^p from .Text and
.Replacement.Text.
With Selection.Find
.Text = ""
.Replacement.Text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll
If you want to remove a character style altogether and have the text take
the formatting of the underlying paragraph style use this line for the
Replacement.Style
Selection.Find.Replacement.Style = ActiveDocument.Styles("Default Paragraph
Font") You won't need the ^p either.
Hope that helps.
Mike
------------------------------
Message: 22
Date: Wed, 22 Mar 2006 11:17:56 +1100
From: "Partridge, Robert" <Robert -dot- Partridge -at- au -dot- unisys -dot- com>
Subject: Finding character styles in Word with VBA
To: "TECHWR-L" <techwr-l -at- lists -dot- techwr-l -dot- com>
Message-ID:
Calling all Word VBA gurus... I'm trying to find both para and char
formats and replace them with other formats in Word XP. I've got an
array of the find styles and another of the replace styles. Finding and
replacing para formats is easy with this code:
For i = 0 To 8
Selection.Find.Style = ActiveDocument.styles(mystyles(i))
Selection.Find.Replacement.Style =
ActiveDocument.styles(replacementstyles(i))
With Selection.Find
.Text = "^p"
.Replacement.Text = "^p"
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
What I can't seem to do is find character styles using the same method.
So I've got a sentence like:
[style a]Something here [style b] and some more text in here[end style
b] and back to the original style.[end style a]
Is there any way to find style b and replace with style a with vba? I
tried using empty find and replace strings or using find any character
(^?) and replace with the find text (^&) but they don't work. I can find
the characteristics of Style B (font color = aqua and text = hidden) and
replace them with the normal characteristics, but I'd still have the
different character style peppered throughout the document.
WebWorks ePublisher Pro for Word features support for every major Help
format plus PDF, HTML and more. Flexible, precise, and efficient content
delivery. Try it today!. http://www.webworks.com/techwr-l