title: VBA code to select table at cursor which avoids a crash when there is no table at the cursor
body: <p>I have the following VBA macro which selects a table at the cursor point, formats the table and formats the text.</p>
  
  <p>I want to avoid it crashing (runtime error) when the cursor is not in a table and instead put up a message like "Select Table First".</p>
  
  <pre><code>Sub FormatTable(control As IRibbonControl)
  '
  ' FormatTable Macro
  '
  
  Selection.Tables(1).Select
  Selection.Tables(1).Style = "Prime Table 1"
  Selection.Style = ActiveDocument.Styles("Normal")
  End Sub
  </code></pre>