View Single Post
 
Old 01-15-2023, 10:45 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

There are multiple possibilities for the selection when the macro is run. The selection might not be in a table, inside a table, include part of a table, include a full table, include (parts of) more than one table.

Graham's code will work when the current selection is situated INSIDE a table.

An alternative way of looking at the problem is to see if any part of any tables is included in the selection and select the first table instance. That alternative is shown in this code.
Code:
Sub SelectATable()
  If Selection.Tables.Count > 0 Then
    Selection.Tables(1).Select
  Else
    MsgBox "There is no table in the current selection", vbCritical + vbOKOnly, "Oh No!"
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote