title: Change Shape color in a loop VBA PPT
body: <p>I need to change Colors of certain Shapes in a slide, based on the criteria if the shape is an EndConnectedShape of certain Connectors (the connectors are selected based on some data in a .txt file, but the data input part works fine).</p>
  
  <p>Although it must be straightforward, the part where I try to get the Shape by its Name is still not working:</p>
  
  <pre><code>Sub test()
      Dim oFSO As FileSystemObject
      Set oFSO = New FileSystemObject
  
      Dim oFS As TextStream
      Dim i, j As Long
  
      Dim filePath, smth As String
      filePath = "C:\MyPath\MyFile.txt"
  
      If oFSO.FileExists(filePath) Then
  
          On Error GoTo Err
  
          Set oFS = oFSO.OpenTextFile(filePath)
          For i = 1 To 1
              smth = VecNames(j)  ' ADDED
              wholeLine1 = oFS.ReadLine
              VecNames = Split(wholeLine1, ",")
  
              wholeLine2 = oFS.ReadLine
              VecSIs = Split(wholeLine2, ",")
  
  
              For j = 1 To UBound(VecNames)
                  With ActivePresentation.Slides(i)
                      For Each oSh In ActivePresentation.Slides(i).Shapes
                          If oSh.Connector And oSh.Name = smth Then
                              'Degub.Print oSh.Name
  
                              oSh.Line.ForeColor.RGB = RGB(255, 0, 0)
                              oSh.Line.Weight = VecSIs(j) * 5
                              strShNm = oSh.ConnectorFormat.EndConnectedShape.Name
  
                              ' NEXT LINE IS NOT WORKING :
                              mySh = ActivePresentation.Slides(i).Shapes(strShNm)
                              ' When tried to change the line above to the one below which is commented out, it DOESN'T work either:
                              ' mySh = Selection.ShapeRange(strShNm)
                              With mySh
                                  mySh.Line.ForeColor.RGB = RGB(255, 0, 0)
                              End With
  
                          ElseIf oSh.Type = msoTextBox Then
                              If mySh.TextFrame.TextRange.Text = VecNames(j) Then
                                  oSh.TextFrame.TextRange.Font.Color = RGB(255, 0, 0)
                              End If
                          End If
                      Next oSh
                  End With
              Next j
          Next i
          oFS.Close
      Else
          MsgBox "The file path is invalid.", vbCritical, vbNullString
          Exit Sub
      End If
      Exit Sub
  
      Err:
          MsgBox "Error while reading the file.", vbCritical, vbNullString
          oFS.Close
          Exit Sub
  End Sub
  </code></pre>
  
  <p>Any idea what am I doing wrong? Thanks! </p>