mardi 12 novembre 2019

How to check if the object is selected?

I need to determine if the object in loop is selected or not. The code is for formatting or adding a title on selected slide. The loop need to check if there is already title on the slide. If it is than if it is the selected slide just need to format, if not then msgbox with information.

// I have marked the problem

    If ActiveWindow.Selection.ShapeRange.Count = 1 Then

               For Each shp In sld.Shapes
                 If shp.Type = msoPlaceholder Then
                  If (shp.PlaceholderFormat.Type = ppPlaceholderCenterTitle _
                   Or shp.PlaceholderFormat.Type = ppPlaceholderTitle) Then
                     If ActiveWindow.Selection.ShapeRange(1) = shp Then // here is the problem 
                          ActiveWindow.Selection.ShapeRange(1).TextFrame.TextRange.Copy
                     Else
                     MsgBox "Every slide can have only one title, the selected slide already has title. ", vbExclamation, "Title exist"
                     Exit Sub
                     End If
                  End If
                 End If
                 Next shp
              ActiveWindow.Selection.ShapeRange(1).TextFrame.TextRange.Copy
              ActiveWindow.Selection.ShapeRange(1).Delete

         sld.Shapes.AddTitle
         Set shp = sld.Shapes.Title
         shp.TextFrame.TextRange.Paste

    Else
        MsgBox "Select only one shape!", vbExclamation, "Multiple shapes"
        Exit Sub
    End If

if statement that check if shp in loop is the selected shape

Aucun commentaire:

Enregistrer un commentaire