Consulting

Results 1 to 4 of 4

Thread: Nightmare with formatting

  1. #1

    Nightmare with formatting

    Hello all,

    I'm having a nightmare with coding Word formatting. Here is the story:

    - Our Word documents are uploaded to a custom-built software that at the moment reads the underlying "Asian text font", rather than the Font or Complex Font of all text. Once this software spits it out, the formatting is all over the place since it is based on the Asian text font, rather than the real font.
    - N.B. half of the documents we're getting are coming from computers that seem to be from Chinese and Korean computers (even though the text is almost always in English or Russian).
    - Since it is not possible to set Asian Text Font to Times New Roman, nor to remove the Asian text font altogether, the plan is to Clear all formatting, which seems to wipe the underlying Asian text font.

    - The issue is, however, that we need to keep the bold in the original document. The solution we came up with is to search through the document for any instances of bold, strip the formatting, and then reintroduce the bold.
    - The code below goes through removing the bold, but I want it also to clear the clearformatting sufficiently well to completely wipe the underlying "Asian text font". Here is what I have. This code only does it for one instance of bold at a time. How do I get it to loop through and do it for all instances? Any help is so much appreciated!!

    This was my original attempt

    Selection.ClearFormatting
    With Selection.Find
    .ClearFormatting
    .Font.Bold = True
    .Replacement.ClearFormatting
    .Replacement.Font.Bold = False
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    And then I tried this
    Dim iCount As Integer
    Selection.HomeKey Unit:=wdStory


    With Selection.Find
    .ClearFormatting
    .Font.Bold = True
    .Execute
    End With


    Do While Selection.Find.found = True And iCount < 1000
    iCount = iCount + 1


    If Selection.Find.found Then

    Selection.ClearFormatting
    Selection.Font.Bold = True


    End If
    Loop


    End Sub
    Last edited by Davecogz84; 09-07-2018 at 10:34 AM.

  2. #2
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location
    This code will change the language ID and clear formatting:

    Sub ChangeLanguageIdAndClearFormatting()
    '
    ' Kilroy
        
        
    Selection.WholeStory
    With Selection
    .LanguageID = wdEnglishUK
    .NoProofing = True
    Application.CheckLanguage = True
    End With
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^?"
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = False 'True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    End Sub

  3. #3
    Hi Kilroy,

    Thanks for the quick reply!

    Unfortunately the Find and Replace function doesn't clear the Asian text font. The only way I've found to do that is to run a Selection.ClearFormatting command. But to run such a command, I need to be looping through the find and replace. I hope that makes sense!

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 9/8/2018
    Dim oRng As Word.Range
      Set oRng = ActiveDocument.Range
      With oRng.Find
        .Font.Bold = True
        While .Execute
          oRng.Select
          Selection.ClearFormatting
          oRng.Font.Bold = True
          oRng.Collapse wdCollapseEnd
        Wend
      End With
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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