title: Excel 2010 VBA: find out if formatting style exists
body: <p>I want to check if an formatting style exists in an Excel2010 document.</p>
  
  <pre><code>On Error Resume Next
  
  Private Function checkStyleName(ByVal strStyleName As String) As Boolean
      Dim objGivenStyle As Excel.Style
  
      Set objGivenStyle = ActiveDocument.Styles(strStyleName) ' try to get formatting style out of list
      If objGivenStyle Is Nothing Then
          ' do something
          checkStyleName = False
      Else
          checkStyleName = True
      End If
  End Function
  </code></pre>
  
  <p>Problem is, <code>Set objGivenStlye = ActiveDocument.Styles(strStyleName)</code> doesn't work at all. What is the best solution - maybe a loop over all existing styles?</p>
  
  <p>THX BKS</p>