Font scaling/spacing/position reset oddity

D

David Turner

In trying to reset font spacing, scaling and position in Word files to remove
extraneous formatting codes once the file is imported into a translation
environment application, this macro:

Sub ScalingSpacingPositionKerning()

Dim rPrg As Paragraph

For Each rPrg In ActiveDocument.Paragraphs

With rPrg.Range.Font

.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0

End With

Next rPrg

End Sub

for some strange reason, doesn't produce such good result as the one below
which obviously takes much longer to run as it trolls through a S&R on every
character. Can anyone see why this could be?

Sub scaling()

Dim aRange

For Each aRange In ActiveDocument.StoryRanges
With aRange.Find
..ClearFormatting
..Replacement.ClearFormatting
..Format = True
..Replacement.Font.Spacing = 0
..Replacement.Font.scaling = 100
..Execute Forward:=True, Replace:=wdReplaceAll, findText:="^?",
ReplaceWith:="^&"
End With

Next aRange

End Sub


Even going down to:

For Each rWrd In rPrg.Range.Words
or
For Each rChr In rWrd.Characters

doesn't seem to improve matters. The S&R macro on every character still does
better.

I'm mystified.

Any help greatly appreciated.

David
 
K

Klaus Linke

Hi David,

You shouldn't need to loop even paragraphs; something like this should work:

With ActiveDocument.Content.Font
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
End With

Not sure what you mean with "doesn't produce such good result" (as looping
each character)...
Does the macro not remove some spacing, scaling...?
Is there anything special about the texts that are left with the wrong
character formatting?

Greetings,
Klaus
 
D

David Turner

Hi Klaus. Thanks for your reply.

Klaus Linke said:
You shouldn't need to loop even paragraphs; something like this should work:

That's what I thought.

With ActiveDocument.Content.Font
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
End With

Not sure what you mean with "doesn't produce such good result" (as looping
each character)...

What I mean is that after running the macro and importing the Word file into
the translation application I use, I still have placeholder "codes"
representing RTF formatting which are materialsed as "text with p{1}aceholder
co{2}des". On looking "inside" these placeholders, the RTF code for {1} looks
like this:
}{lang1036\langfe 1041 \langnp1036 \hicn \ aft0 \dbch \ af11 \ loch \ fo \
hich etc.
Which would seem to indicate a language change or some sort of automatic
language detection of two languages.

adding:

..LanguageID = wdFrench

doesn't remove these codes.

With ActiveDocument.Content.Font
.Spacing = 0
..Scaling = 100
.Position = 0
..Kerning = 0
..LanguageID = wdFrench
End With

but searching for "^?" and replacing it with "^&" .LanguageID = wdFrench does.
Any idea how to reset the language and/or turn off automatic
language/keyboard detection more thoroughly without this long S&R?

Many thanks.

David
 
K

Klaus Linke

Maybe look if Tools > Options > Save > Embed language-specific data (or
something like that) is checked?
I know that it's often hard to impossible to get rid of those codes, though,
especially if you are dealing with exotic languages and symbols.
Sometimes I've reverted to desperate measures like cutting, then pasting as
unformatted text...

Greetings,
Klaus
 
D

David Turner

Klaus Linke said:
Maybe look if Tools > Options > Save > Embed language-specific data (or
something like that) is checked?

Tried that as well. Turned off everything in sight in fact but no joy.

With ActiveDocument
..AcceptAllRevisions
..TrackRevisions = False
..ShowRevisions = False
..ShowGrammaticalErrors = False
..ShowSpellingErrors = False
..AutoHyphenation = False
..HyphenateCaps = False
..RemoveSmartTags
..EmbedSmartTags = False
..EmbedLinguisticData = False
Application.CheckLanguage = False
End With
I know that it's often hard to impossible to get rid of those codes, though,
especially if you are dealing with exotic languages and symbols.

You're telling me!
Sometimes I've reverted to desperate measures like cutting, then pasting as
unformatted text...

Yes, hence my S&R on each character. Copying the whole file to a new
document without going through the clipboard seems to do the trick although
it's hard to avoid mangling format and page layout. Perhaps cycling through
each paragraph, sentence, word and character checking the font for bold,
italic, etc. and then cutting/pasting as unformatted text at the appropriate
level could be a possible solution?

Thanks again for your suggestions.

BR,
David
 
K

Klaus Linke

David Turner said:
You're telling me!
:-(


Yes, hence my S&R on each character. Copying the whole file to a new
document without going through the clipboard seems to do the trick
although
it's hard to avoid mangling format and page layout. Perhaps cycling
through
each paragraph, sentence, word and character checking the font for bold,
italic, etc. and then cutting/pasting as unformatted text at the
appropriate
level could be a possible solution?

Like you, I've spent much too much time already trying such desperate (and
slow) methods, without really finding an adequately fast and foolproof
solution.

In my case, the goal is mostly trying to keep Word from switching the font
in unpredictable ways.
Depending on the language information (that you're seeing in the RTF), Word
will switch between fonts that it deems appropriate for those
languages/characters/symbols.
Thanks again for your suggestions.

Thank you! The Find/Replace on the character level is something I had tried
before, but forgotten about.

To get some control, I try to use big Unicode fonts if possible, and define
that font in the style for all the possible "language families":
myStyle.Font.Name="Arial Unicode MS"
myStyle.Font.NameAscii="Arial Unicode MS"
myStyle.Font.NameBi="Arial Unicode MS"
myStyle.Font.NameFarEast="Arial Unicode MS"
myStyle.Font.NameOther="Arial Unicode MS"

I suspect though that this doesn't really get rid of the embedded info you
see in the RTF (... I'll check next time the problem crops up), but just
eliminates some bad consequences of those codes (i.e. Word switching to
another font by itself).

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