Consulting

Results 1 to 6 of 6

Thread: If statement with two conditions for two different presentations

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location

    If statement with two conditions for two different presentations

    Hello all,

    I'm learning PowerPonit VBA. Recently I got stuck at problem. I have two different presentations. First one: Title and subtitle are the same text box ("Title") Second one: Title and subtitle are two different text boxes. Main purpose is to check colour RGB values for title and subtitle. I tried different approaches and separately it works. I think I don't understand and make a mistake in if function. I think code always "sees" Title although there is Else. Separately it works but I can't make it work together: Check if there is textbox "Subtitle" if yes check colours for two textboxes if not check colour for "Title" first paragraph and second "Paragraph". I'm not also sure if with For function I'm checking every slide from beginning including master slide? Thanks in advance for your help.


    With shpSlide2    
            .TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
            .TextFrame.TextRange.Font.Size = 7
            .TextFrame.TextRange.Font.Bold = True
                           
            'For Each shp In ActiveDesigns.SlideMaster.Shape
            For Each Slide In ActivePresentation.Slides
            For Each shp In Slide.Shapes
            
            Set shp2 = Shape
                      
            If shp.HasTextFrame And shp.Name Like "Subtitle" = True Then
            
            N = shp.TextFrame.TextRange.Font.Color
                     
            B = N \ 65536
            G = (N - B * 65536) \ 256
            R = N - B * 65536 - G * 256
            
            .TextFrame.TextRange.Characters.Text = "Subtitle: " & "R:" & R & " G:" & G & " B:" & B
            .Fill.ForeColor.RGB = N
         
            Else
            
            If shp.Name Like "Subtitle*" = False And shp2.HasTextFrame And shp2.Name Like "Title*" Then
            
            N = shp2.TextFrame.TextRange.Paragraphs(2).Characters(1).Font.Color
            
            B = N \ 65536
            G = (N - B * 65536) \ 256
            R = N - B * 65536 - G * 256
            
            .TextFrame.TextRange.Characters.Text = "Subtitle: " & "R:" & R & " G:" & G & " B:" & B
            .Fill.ForeColor.RGB = N
    
    
    
    
            End If
            End If
            Next
            Next
                    
        End With

  2. #2
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location
    I was recently working on this and have some progress. I don't understand one thing. How works something like this: If shp("Subtitle").Visible = False Then
    Does it mean that there is no shape Subtitle on slide or there is shape Subtitle on slide but with visibility turned off in Selection Pane? Is there way to check if shape DO NOT EXIST on slide? I mean as a condition?
    If there is no shp("Subtitle") on slide Then ?

    Thanks in advance

  3. #3
    VBAX Regular
    Joined
    Mar 2017
    Posts
    23
    Location
    How works something like this: If shp("Subtitle").Visible = False Then
    Does it mean that there is no shape Subtitle on slide or there is shape Subtitle on slide but with visibility turned off in Selection Pane?
    It means that visibility is turned off - but the shape still exists.

    Is there way to check if shape DO NOT EXIST on slide? I mean as a condition?
    If there is no shp("Subtitle") on slide Then ?
    Yes. You can use this function to find a shape with a particular name (as in the name you see in the selection pane):

    Public Function getShapeByName(shapeName As String, slSlide As Slide) As Shape
      Dim s As Shape
      For Each s In slSlide.Shapes
        If s.Name = shapeName Then
          Set getShapeByName = s
          Exit Function
        End If
      Next
      Set getShapeByName = Nothing
    End Function
    and check whether or not the return is nothing. For example:

    Public Sub ShapeTest()
    
    
      Dim myShape As Shape
      Dim mySlide As Slide
      Set mySlide = Application.ActiveWindow.View.Slide
    
    
      Set myShape = getShapeByName("Rectangle 3", mySlide)
    
    
      If myShape Is Nothing Then
        MsgBox "No shape found"
      Else
        MsgBox "Shape found"
      End If
    
    
    End Sub

  4. #4
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location
    Thank you for your help!
    All is clear now

  5. #5
    Hi all,

    Could you please post the whole VBA Code. It is very useful for me.

    Thanks

  6. #6
    Perhaps you could post the code here?

    Thanks

Posting Permissions

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