Consulting

Results 1 to 10 of 10

Thread: Convert fake / faux small caps words to true / real SmallCaps words

  1. #1

    Convert fake / faux small caps words to true / real SmallCaps words

    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 !!!

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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)
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    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

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by iwonder View Post
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  6. #6
    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

  7. #7
    hey Greg
    Thanks for your code !
    I'll test it later cause I have to go now
    have a nice day/night
    Bernard

  8. #8
    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/show...old-etc-format
    (bottom of page 2)

    and.... they are !!!!
    Then, thanks again and again and again !!!!
    One thing : could you tell what "Case 65 to 90" means ?

  9. #9
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  10. #10
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by gmaxey View Post
    See if this helps:

    Good one
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •