Thread: [Solved] Table named after first cell
View Single Post
 
Old 05-15-2019, 06:49 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

No harm, no foul. My point is that you didn't indicate from the start that your cell content could contain text that was invalid for a bookmark name, that it could be two or more words separated by spaces or that your really only wanted the first word.


If you really only want the first word then both mine and Paul's code could have been different:

Code:
Sub Demo()
Dim lngIndex As Long
Dim oTbl As Table
  For lngIndex = 2 To ActiveDocument.Tables.Count
    Set oTbl = ActiveDocument.Tables(lngIndex)
    With oTbl
      .Range.Bookmarks.Add Trim(.Cell(1, 1).Range.Words(1)), .Range
    End With
  Next lngIndex
End Sub
Now still, if the first "word" happens to be a number or if there is no first word (empty cell), you will still get and error.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 05-15-2019 at 12:09 PM.
Reply With Quote