Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
vio69 pe Simpatie
Femeie
25 ani
Botosani
cauta Barbat
25 - 50 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [WORD] Change Language for All Text in Active Document [VBA] Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
Source:


Sub DocumentChangeLanguage2()

Dim r As Range
Dim p As Paragraph

For Each r In ActiveDocument.StoryRanges
    For Each p In r.Paragraphs
        p.Range.LanguageID = wdRomanian
    Next p
Next r
   
End Sub


The code doesn't do it for Text Frames or Shapes, but the code in the next post will.

Modificat de TRaP (acum 5 ani)


pus acum 5 ani
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
Source:



Sub DocumentChangeLanguage2All()

Application.ScreenUpdating = False

Dim rngStory As word.Range
Dim lngJunk As Long
Dim oShp As Shape
    lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType

    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.EscapeKey


For Each rngStory In ActiveDocument.StoryRanges
  'Iterate through all linked stories
  Do
    On Error Resume Next
    rngStory.LanguageID = wdRomanian
    Select Case rngStory.StoryType
      Case 6, 7, 8, 9, 10, 11 '1, 2, 3, 4, 5, 12, 13, 14, 15, 16, 17
      ' more about StoryTypes: https://docs.microsoft.com/en-us/office/vba/api/word.wdstorytype
        If rngStory.ShapeRange.Count > 0 Then
          For Each oShp In rngStory.ShapeRange
            If oShp.TextFrame.HasText Then
               oShp.TextFrame.TextRange.LanguageID = wdEnglishAUS
            End If
          Next
        End If
      Case Else
        'Do Nothing
    End Select
    On Error GoTo 0
    'Get next linked story (if any)
    Set rngStory = rngStory.NextStoryRange
  Loop Until rngStory Is Nothing
Next

Application.ScreenUpdating = True

End Sub


pus acum 5 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
This line in the post above:
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
inserted a paragraph in the header of the document - when the document didn't have a header - moving all text down with 1 line (the code created a header made of an empty paragraph).

To fix that, I edited the post above and added in color 2 new lines - they open header then exit it, which is enough to make the empty paragraph "back off".

Also added Application.ScreenUpdating lines to prevent screen flickering while the code does its thing.


_______________________________________


pus acum 2 ani
   
Pagini: 1  

Mergi la