Text Replacement

R

Robert Young

If I have

Dim Field F1

It is my understanding that

F1.Result

represents the text in the field. (Correct me if I am wrong).

How could I replace any character style formatting with direct
formatting applied to the text? I would like to be able to go through
the text in the field, find all the character style formatting, remove
the style formatting and replace with the actual formatting -- (if the
style does bold, make the text bold without style formatting -- or in
addition to--I can leave the style in place).
 
D

Doug Robbins - Word MVP

The way to apply character formatting to a field is to use the charformat
switch and then apply the desired formatting to the first character in the
..Code of the field. That can either be done manually or you could create a
macro to modify the .Code of all of the fields in a document and then
..Update them to display the result with required character formatting.

I suspect however that there may be more to what you are wanting to do.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
R

Robert Young

The way to apply character formatting to a field is to use the charformat
switch and then apply the desired formatting to the first character in the
.Code of the field.  That can either be done manually or you could create a
macro to modify the .Code of all of the fields in a document and then
.Update them to display the result with required character formatting.

I suspect however that there may be more to what you are wanting to do.

I don't want to change the entire field text. I want to find every
character that has a character style applied, then apply that
formatting to that character. If the style has bold. The character
gets bold applied directly with out the style. If no style, no change
in that character.
 
D

Doug Robbins - Word MVP

It's a strange requirement, but we would need to know the names of the
character styles and the definition of them to give you a complete response.

Also, you are going to have to create a style that does no have any
formatting to apply to the characters that are formatted with a Style and
then apply the desired font attribute. I created the character style
NoCharFormat for use with the following macro, which replaces the Strong
style wiht the NoCharFormat style and then emboldens the font of the
characters to which the Strong style had been applied:

Dim afield As Field, i As Long
For Each afield In ActiveDocument.Fields
With afield.Result
For i = 1 To .Characters.Count
If .Characters(i).Style = "Strong" Then
.Characters(i).Style = "NoCharFormat"
.Characters(i).Font.Bold = True
End If
Next i
End With
Next afield




--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.

The way to apply character formatting to a field is to use the charformat
switch and then apply the desired formatting to the first character in the
.Code of the field. That can either be done manually or you could create a
macro to modify the .Code of all of the fields in a document and then
.Update them to display the result with required character formatting.

I suspect however that there may be more to what you are wanting to do.

I don't want to change the entire field text. I want to find every
character that has a character style applied, then apply that
formatting to that character. If the style has bold. The character
gets bold applied directly with out the style. If no style, no change
in that character.
 

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