Log in

View Full Version : Array of Variant with shapes not visible on slide



YorickG
10-16-2017, 03:46 AM
Hello all, probably a very newbie question, however I can't figure it out.

I want to check RGB values of text in shape. Shapes have random names (for example Title, Title 2, Title 3). My code works in case there is shape "Title" and "Title 2" present on slide. How to modify this code to work with only one shape present. ID titles are random. So it should work with name for example from range Title - Title 10.


Dim N As Long, R As Long, G As Long, B As Long Dim shp As Shape
Dim titleShp() As Variant



On Error Resume Next
For i = 1 To N
Next i


If ActiveWindow.View.Slide.Shapes("A1a").Visible = False Then
MsgBox "There is no color palette on this slide :)"
End If


titleShp = Array("Title", "Title 2")


'ACCENT1 - CODE

With ActiveWindow.View.Slide.Shapes("A1a")

.Fill.ForeColor.RGB = ActiveWindow.View.Slide.Shapes.Range(titleShp).TextFrame.TextRange.Font.Col or
.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
.TextFrame.TextRange.Font.Size = 7
.TextFrame.TextRange.Font.Bold = True

N = ActiveWindow.View.Slide.Shapes.Range(titleShp).TextFrame.TextRange.Font.Col or

B = N \ 65536
G = (N - B * 65536) \ 256
R = N - B * 65536 - G * 256

.TextFrame.TextRange.Characters.Text = "Title: " & "R:" & R & " G:" & G & " B:" & B


End With

Paul_Hossler
10-16-2017, 05:22 PM
Not exactly clear what the intent of your macro is, but taking a guess ....




Option Explicit

Sub test()

Dim N As Long, R As Long, G As Long, B As Long
Dim shp As Shape, shpPalette As Shape

If ActiveWindow.View.Slide.Shapes("A1a").Visible = False Then
MsgBox "There is no color palette on this slide :)"
End If

Set shpPalette = ActiveWindow.View.Slide.Shapes("A1a")

With shpPalette
.Fill.ForeColor.RGB = ActiveWindow.View.Slide.Shapes.Range(titleShp).TextFrame.TextRange.Font.Col or
.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
.TextFrame.TextRange.Font.Size = 7
.TextFrame.TextRange.Font.Bold = True
End With

For Each shp In ActiveWindow.View.Slide.Shapes

If shp.Name Like "Title*" Then
N = shp.TextFrame.TextRange.Font.Color

B = N \ 65536
G = (N - B * 65536) \ 256
R = N - B * 65536 - G * 256

MsgBox shp.TextFrame.TextRange.Characters.Text = "Title: " & "R:" & R & " G:" & G & " B:" & B
End If
Next

End Sub

YorickG
10-17-2017, 01:30 AM
Thank you very much Paul. you set me on right track with
If shp.Name Like "Title*" Then
That's exactly what I was looking for. I modified my code and now it's working the way I planned. I added also .Paragraphs(1) (2) etc so now I can check RGB values of specific paragraph.
From what I learned thanks to you I understand that having an array will require all shapes to be visible/present on slide. "Like" will help with random shape names. For learning purpose I have a question. Is there a way to have an array which behaves somehow like "Like". So for example I have an array with shape names but they behave like an "option".
Bets regards

Paul_Hossler
10-17-2017, 06:52 AM
Not sure about 'option' but an array would work





Option Explicit

Sub test()

Dim N As Long, R As Long, G As Long, B As Long
Dim shp As Shape, shpPalette As Shape
Dim aShapesToUse As Variant
Dim i As Long

If ActiveWindow.View.Slide.Shapes("A1a").Visible = False Then
MsgBox "There is no color palette on this slide :)"
End If

Set shpPalette = ActiveWindow.View.Slide.Shapes("A1a")

With shpPalette
.Fill.ForeColor.RGB = ActiveWindow.View.Slide.Shapes.Range(shpPalette).TextFrame.TextRange.Font.C olor
.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
.TextFrame.TextRange.Font.Size = 7
.TextFrame.TextRange.Font.Bold = True
End With


'------------------------------------------------------------------ use an array
aShapesToUse = Array("Title", "Title 1", "Title 2")
For i = LBound(aShapesToUse) To UBound(aShapesToUse)
Set shp = ActiveWindow.View.Slide.Shapes(aShapesToUse(i))

N = shp.TextFrame.TextRange.Font.Color

B = N \ 65536
G = (N - B * 65536) \ 256
R = N - B * 65536 - G * 256

MsgBox shp.TextFrame.TextRange.Characters.Text = "Title: " & "R:" & R & " G:" & G & " B:" & B
Next

End Sub