Styles & Formatting

P

Patrick386

Hello!

Is there a 'simple' way to remove from a selected text all its styles and keep the formatting?

What I've tried so far with vba is:
to loop on the BuildIn styles and then look for the text that uses the style. Then copy the settings of the selection, apply the Normal Style to it, and then paste back the all selection's settings except the style.

This solution works except when the selection is composed by multiple settings such as different FontColors, FontSize.... that the user applied after having set the style to selection.

if you have any good idea, it would be more than welcome
Thanks!
 
P

Patrick386

Not really what I've been expecting, but this code below (given by Klaus Linke in another forum) gives you the list but in string type. so you will not have access to the properties or methods of the formats.



Dim myC As CommandBarComboBox, i As Long
Set myC = CommandBars("Formatting").Controls("&Style:")

'Or use the Index: better if the language may vary Set myC = CommandBars.FindControl(ID:=1732)
With myC
For i = 1 To .ListCount
Debug.Print .List(i)
Next i
End With



If it's shown in the pan, it must be stored somewhere.. but don't know where yet.

Best regards.

"Patrick386" <[email protected]> a écrit dans le message de [email protected]...
Hello!

Is there a 'simple' way to remove from a selected text all its styles and keep the formatting?

What I've tried so far with vba is:
to loop on the BuildIn styles and then look for the text that uses the style. Then copy the settings of the selection, apply the Normal Style to it, and then paste back the all selection's settings except the style.

This solution works except when the selection is composed by multiple settings such as different FontColors, FontSize.... that the user applied after having set the style to selection.

if you have any good idea, it would be more than welcome
Thanks!
 
K

Klaus Linke

Patrick386 said:
Is there a 'simple' way to remove from a selected text all its
styles and keep the formatting?

None that I know. I've tried to save as RTF and delete all style definitions, but that didn't work too well.
RTF saves both the styles and the actual formatting, so it did work in a way. But I don't know much about the RTF format and corrupted the docs along the way. Or maybe Word doesn't like to import a doc without any style definitions. Usually I ended up with the styles pane showing say "Normal + Bold" several times, and it was difficult to clean the mess up.

If your goal is the same as it was for me, to clean up docs:

You can create a new document. In it, define all the same styles of the document.
But make all paragraph styles based on "Normal", with no additional formatting.
And make all character styles based on the "Default Paragraph Font", again with no additional formatting.

Then, copy the text from your doc into this new document.

All formatting you still see is manual formatting. So you can go ahead and tag things you want to keep (say, bold and italic), discard all the rest (ResetFont, ResetPara), turn the tags back into formatting, and paste the whole thing back.

Regards,
Klaus
 

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