Consulting

Results 1 to 7 of 7

Thread: Change language

  1. #1

    Change language

    Hello,

    i'm seeking to modify the attached macro to change the language to in all slides to numbers only, this macro scopes all slides and shapes and changes the language for all text to be English US

    i just want it to scope all numbers only


    attached two sample files for before and after case.


    in before file you will find all text with numbers in English South Africa language


    in after file you will find all numbers set to English US and text still in English South Africa

    Sub SetLangUS()
    Dim scount, j, k, fcount
    scount = ActivePresentation.Slides.Count
    For j = 1 To scount
    fcount = ActivePresentation.Slides(j).Shapes.Count
    For k = 1 To fcount 'change all shapes:
    If ActivePresentation.Slides(j).Shapes(k).HasTextFrame Then
    ActivePresentation.Slides(j).Shapes(k).TextFrame _
    .TextRange.LanguageID = msoLanguageIDEnglishUS
    End If
    Next k
    fcount = ActivePresentation.Slides(j).NotesPage.Shapes.Count
    For k = 1 To fcount 'change all shapes:
    If ActivePresentation.Slides(j).NotesPage.Shapes(k).HasTextFrame Then
    ActivePresentation.Slides(j).NotesPage.Shapes(k).TextFrame _
    .TextRange.LanguageID = msoLanguageIDEnglishUS
    End If
    Next k
    Next j
    End Sub
    Before.zip
    After.zip



    cross-posting link: here

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    It would be a fair bit of work to make the code pick up numbers only - especially as your numbers are in a table which the current code will not even see.

    The question then is WHY - Splellchecker would not flag numbers anyway would it?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Hi John,

    Thanks a lot for your reply.

    well i just need it because in other languages, numbers should take another language code especially when we deal with RTL languages

    for ex, in Arabic text will take Arabic but numbers should remain in EN US.

    i tried to do it in regex but still can't get the final code

    please check the below code if possible to modify it to change the language for numbers


    Sub use_regex()
    Dim regX As Object
    Dim osld As Slide
    Dim oshp As Shape
    Dim strInput As String
    Dim b_found As Boolean
    Dim iRow As Integer
    Dim iCol As Integer

    Set regX = CreateObject("vbscript.regexp")
    With regX
    .Global = True
    .Pattern = "[0-9]"
    End With
    For Each osld In ActivePresentation.Slides
    For Each oshp In osld.Shapes
    If oshp.HasTable Then
    For iRow = 1 To oshp.Table.Rows.Count
    For iCol = 1 To oshp.Table.Columns.Count
    strInput = oshp.Table.Cell(iRow, iCol).Shape.TextFrame.TextRange.Text
    b_found = regX.Test(strInput)
    If b_found = True Then
    strInput = regX.Replace(strInput, "$1")
    oshp.Table.Cell(iRow, iCol).Shape.TextFrame.TextRange = strInput
    End If
    Next iCol
    Next iRow
    Else
    If oshp.HasTextFrame Then
    If oshp.TextFrame.HasText Then
    strInput = oshp.TextFrame.TextRange.Text
    b_found = regX.Test(strInput)
    If b_found = True Then
    strInput = regX.Replace(strInput, "$1.$2")
    oshp.TextFrame.TextRange = strInput
    End If
    End If
    End If
    End If
    Next oshp
    Next osld
    Set regX = Nothing
    End Sub




  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    I don't really need to "Check the below code" because it has been lifted from our website. It is designed to do something else entirely and cannot be used to changed the number language.

    I still don't see what you are trying to achieve (or rather why) but this code should just change the number language. Just top of my head code - not tested.

    Sub just_Numbers()
    Dim iCol As Integer
    Dim iRow As Integer
    Dim otbl As Table
    Dim osld As Slide
    Dim oshp As Shape
    For Each osld In ActivePresentation.Slides
    For Each oshp In osld.Shapes
    Select Case oshp.HasTable
    Case False
    If oshp.HasTextFrame Then
    If oshp.TextFrame.HasText Then Call fixLang(oshp)
    End If
    Case True
    Set otbl = oshp.Table
    For iRow = 1 To otbl.Rows.Count
    For iCol = 1 To otbl.Columns.Count
    If otbl.Cell(iRow, iCol).Shape.TextFrame.HasText Then Call _
    fixLang(otbl.Cell(iRow, iCol).Shape)
    Next iCol
    Next iRow
    End Select
    Next oshp
    Next osld
    End Sub
    
    
    Sub fixLang(oshp As Shape)
    Dim W As Long
    For W = 1 To oshp.TextFrame.TextRange.Words.Count
    If IsNumeric(oshp.TextFrame.TextRange.Words(W)) Then
    oshp.TextFrame.TextRange.Words(W).LanguageID = msoLanguageIDEnglishUS
    End If
    Next W
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    Hi John,

    really i don't have enough words to thank you for that great work. your code works great but there are few comments about it and i will be so much appreciated if it can be solved because you can't imagine how much i need it badly.

    1- it doesn't apply on notes on every slide

    2- orders like (9:05 AM) , (1/14/2019) , (1-14-2019) . the code doesn't apply on them too

    Thanks in advance brother and i hope that you can help me about

    Cheers

  6. #6
    can't we just add regex pattern to look for and apply to for the missing two cases mentioned above like:

    .Pattern = "[0-9]:[0-9]"
    .Pattern = "[0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]"
    .Pattern = "[0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]"


    and of course to apply on notes too

  7. #7
    i tried several times in regex but still nothing!!

Tags for this Thread

Posting Permissions

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