Change All Uppercase Sentences to SentenceCase in PowerPoint VBA

Jakov93
NewLounger
Posts: 9
Joined: 26 Feb 2024, 21:56

Change All Uppercase Sentences to SentenceCase in PowerPoint VBA

Post by Jakov93 »

Hi,
I have such case
Image
I have uppercase sentences in title and body text, so I want to change all uppercase sentences to normal sentence case.
I tried many macros but all failed to do what I want such as

Code: Select all

Sub SetSentenceCase()
  Dim objSlide As slide, objShape As shape
  For Each objSlide In ActivePresentation.Slides
    For Each objShape In objSlide.Shapes
      If objShape.Type = msoPlaceholder Then
        If objShape.PlaceholderFormat.Type = ppPlaceholderObject Then
          objShape.TextFrame.textRange.ChangeCase ppCaseSentence
        End If
      End If
    Next objShape
  Next objSlide
End Sub
Also,
https://powerpointprogram.indezine.com/ ... %20button.
my file
https://www.upload.ee/files/16410288/Demo.pptx.html
Thanks

User avatar
HansV
Administrator
Posts: 78991
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Change All Uppercase Sentences to SentenceCase in PowerPoint VBA

Post by HansV »

Try this version:

Code: Select all

Sub SetSentenceCase()
    Dim objSlide As Slide, objShape As Shape
    For Each objSlide In ActivePresentation.Slides
        For Each objShape In objSlide.Shapes
            If objShape.HasTextFrame Then
                objShape.TextFrame.TextRange.ChangeCase ppCaseSentence
            End If
        Next objShape
    Next objSlide
End Sub
Best wishes,
Hans

Jakov93
NewLounger
Posts: 9
Joined: 26 Feb 2024, 21:56

Re: Change All Uppercase Sentences to SentenceCase in PowerPoint VBA

Post by Jakov93 »

HansV wrote:
19 Mar 2024, 19:41
Try this version:
Thanks so much HansV
Dear HansV,
The code works fine, but the only problem with it, it's change any uppercase word or character to lowercase
for example it changes (dipeptide D-alanyl-D-alanine) to (dipeptide d-alanyl-d-alanine) which is not suitable for some medical terms
Can we use (if condition) to change the case only if the sentence is in uppercase, such as (MECHANISMS OF ACTION), otherwise keep it unchanged
I modified your code

Code: Select all

Sub SetSentenceCase()
    Dim objSlide As slide, objShape As shape
    For Each objSlide In ActivePresentation.Slides
        For Each objShape In objSlide.Shapes
            If objShape.HasTextFrame Then
                If objShape.TextFrame.textRange Like UCase(objShape.TextFrame.textRange) Then
                    objShape.TextFrame.textRange.ChangeCase ppCaseTitle
                End If
            End If
        Next objShape
    Next objSlide
End Sub
Now the code is OK, but only change if the entire textbox is in uppercase, if the text box is mixed (upper and lowercase sentences), it left it unchanged at all, so can we make further modification to change any sentences in uppercase everywhere to sentencecase?
Thanks again

User avatar
HansV
Administrator
Posts: 78991
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Change All Uppercase Sentences to SentenceCase in PowerPoint VBA

Post by HansV »

That would be complicated.
Best wishes,
Hans

Jakov93
NewLounger
Posts: 9
Joined: 26 Feb 2024, 21:56

Re: Change All Uppercase Sentences to SentenceCase in PowerPoint VBA

Post by Jakov93 »

Thanks HanV
Best Wishes