View Single Post
 
Old 11-26-2020, 02:57 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

That is an interesting question. My first thought is that it is due to the font metrics of the typeface you had chosen. Some fonts don't appear to have the same problem but some do.

A second possibility is the type of justification being applied. Using the GUI, you can have one type of text justification but if you play with the VBA code there are actually a whole range of justification commands that could be applied to the text. There must be a complex set of rules applied that look at the length of words in the line to determine wrapping points and this appears to impact the right border alignment. Some of these options do give you an aligned right justification of those characters but it may depend on the content of the line itself. You would need to do more testing though as we only have a single paragraph to test in that example you posted.
Code:
Sub aTest()
  ActiveDocument.Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
  ActiveDocument.Range.ParagraphFormat.Alignment = wdAlignParagraphJustifyHi
  ActiveDocument.Range.ParagraphFormat.Alignment = wdAlignParagraphJustifyMed
  ActiveDocument.Range.ParagraphFormat.Alignment = wdAlignParagraphJustifyLow
  ActiveDocument.Range.ParagraphFormat.Alignment = wdAlignParagraphDistribute
  ActiveDocument.Range.ParagraphFormat.Alignment = wdAlignParagraphThaiJustify
End Sub
If you arrange your screen so you can see the document and the code, step through each of the lines of code (by pressing F8) and see the effect on the page layout. Is there one of those options that gives you an acceptable result in ALL instances?

You might want to do some google searching on these VBA alignment options. Perhaps it is documented somewhere what the different options actually do to your text.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote