PDA

View Full Version : If statement with two conditions for two different presentations



YorickG
02-26-2018, 01:47 AM
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

YorickG
02-28-2018, 01:10 AM
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

neilt17
03-09-2018, 12:56 PM
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

YorickG
04-13-2018, 07:52 AM
Thank you for your help!
All is clear now :thumb

selva_235
04-23-2018, 06:43 AM
Hi all,

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

Thanks

selva_235
04-29-2018, 10:18 PM
Perhaps you could post the code here?

Thanks