Consulting

Results 1 to 4 of 4

Thread: Array of Variant with shapes not visible on slide

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

    Array of Variant with shapes not visible on slide

    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.Color
            .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.Color
             
            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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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.Color
        .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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location
    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

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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.Color
            .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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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