View Full Version : Convert fake / faux small caps words to true / real SmallCaps words
iwonder
07-09-2017, 11:15 AM
Hi all
Faux small caps are often used in PDF files made with publishing tools such as InDesign
When exporting such PDF to Word docs files, faux small caps are kept.
(I'm only concerned here with words beginning with a big capital letter, followed by smaller capital letters.)
Such typography habit is often used for authors last names in bibliographies.
The question here is : how to convert fake small caps words to true SmallCaps words with some VBA code (in the whole active document)?
I searched the internet without any success...
Help would be welcome !!!
Paul_Hossler
07-09-2017, 03:52 PM
Q: How do you tell fake SC from 'real' SC?
Some typefaces don't have a true SC but just change the point size (IIRC)
iwonder
07-09-2017, 04:36 PM
Shift-F1 shows all formats of the selection
if "Small capitals" is not displayed there -> fake SC
what i need is "Small capitals" displayed in this pane: this is what I'm calling real SC
Changing point size gives what I'm calling fake SC
Paul_Hossler
07-09-2017, 06:27 PM
Shift-F1 shows all formats of the selection
if "Small capitals" is not displayed there -> fake SC
what i need is "Small capitals" displayed in this pane: this is what I'm calling real SC
Changing point size gives what I'm calling fake SC
What I meant was "How does VBA tell fake SC from real SC? I.e. what formatting attributes can VBA look for?"
For example, If the text is Upper Case and Font Size < Normal style font size, then the text is fake SC
gmaxey
07-09-2017, 07:55 PM
See if this helps:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/9/2017
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "<[A-Z]*>"
.MatchWildcards = True
While .Execute
With oRng
If Len(.Text) > 1 Then
Select Case Asc(.Characters(2))
Case 65 To 90
If .Characters(2).Font.Size < .Characters(1).Font.Size Then
'Convert faux small caps.
.Start = oRng.Start + 1
.Font.Size = oRng.Characters(1).Previous.Font.Size
.Text = LCase(oRng.Text)
.Start = oRng.Start - 1
.Font.SmallCaps = True
End If
End Select
End If
.Collapse wdCollapseEnd
End With
Wend
End With
lbl_Exit:
Exit Sub
End Sub
iwonder
07-09-2017, 09:01 PM
Paul,
An upper case character (of any size) followed by one or more upper case characters with a smaller size (one and only), is a fake SC word : it looks like a small capital word, but it's not :)
iwonder
07-09-2017, 09:03 PM
hey Greg
Thanks for your code !
I'll test it later cause I have to go now
have a nice day/night
Bernard
iwonder
07-09-2017, 09:36 PM
Greg,
I couldn't wait this evening, I had to test it now !!!
and..... it does what it's supposed to !!!
As you maybe guessed, my goal was that small capitals produced by your code, had to be recognized as true smallcaps by your previous code in that post :
http://www.vbaexpress.com/forum/showthread.php?46717-Solved-delete-all-styles-but-to-keep-the-font-bold-etc-format
(bottom of page 2)
and.... they are !!!! :yes
Then, thanks again and again and again !!!!
One thing : could you tell what "Case 65 to 90" means ?
gmaxey
07-10-2017, 04:43 AM
Basically it is evaluating for A to Z. Consider this:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/10/2017
Dim oRng As Range
Dim lngIndex As Long
Set oRng = ActiveDocument.Range
For lngIndex = 1 To 26
oRng.InsertAfter Chr(64 + lngIndex)
Next
For lngIndex = 1 To Len(oRng.Text)
If MsgBox(oRng.Characters(lngIndex) & " is represented by ASCII Character - " _
& Asc(Mid(oRng.Text, lngIndex, 1)), vbOKCancel, "DEMO") = vbCancel Then Exit For
Next
lbl_Exit:
Exit Sub
End Sub
Here is an alternative.
Sub ScratchMacroII()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/9/2017
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "<[A-Z]*>"
.MatchWildcards = True
While .Execute
With oRng
If Len(.Text) > 1 Then
If .Characters(2) Like "[A-Z]" Then
If .Characters(2).Font.Size < .Characters(1).Font.Size Then
'Convert faux small caps.
.Start = oRng.Start + 1
.Font.Size = oRng.Characters(1).Previous.Font.Size
.Text = LCase(oRng.Text)
.Start = oRng.Start - 1
.Font.SmallCaps = True
End If
End If
End If
.Collapse wdCollapseEnd
End With
Wend
End With
lbl_Exit:
Exit Sub
End Sub
Paul_Hossler
07-10-2017, 05:27 AM
See if this helps:
Good one :thumb
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.