View Single Post
 
Old 08-24-2022, 04:12 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 a couple of tricks involved here. First is to avoid an error if the selection doesn't include any table elements. Second is to avoid having the end of cell marker as part of your string.
Code:
Sub Macro1()
  Dim str As String, aCell As Cell
  If Selection.Tables.Count > 0 Then
    str = Selection.Cells(1).Range.Text
    str = Left(str, Len(str) - 2)
  End If
  MsgBox "Text in first selected cell: " & str
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote