0
votes

I try to copy the text from the table in Word to the text, but after the text is overwritten, it appears in the text "black" dot. Please, can you tell me where I am wrong?

Dim rngStory   As Range    
    Name_1 = ActiveDocument.Tables(1).Cell(1, 2)        
    For Each rngStory In ActiveDocument.StoryRanges    
      With rngStory.Find    
      .Text = "<<name>>"    
        .Replacement.Text = Name_1    
        .Wrap = wdFindContinue    
      .Execute Replace:=wdReplaceAll    
      End With        
  Next rngStory

enter image description here

1
This is because a table cell contains two characters that are responsible for the internal cell structures, behind the scenes: a Chr(13) and a Chr(7). These need to be "trimmed" from the text (Name_1). See this: stackoverflow.com/a/49533912/3077495Cindy Meister

1 Answers

0
votes

Try:

Name_1 = Split(ActiveDocument.Tables(1).Cell(1, 2).Range.Text, vbCr)(0)

or, if there may be more than one paragraph in the cell:

Name_1 = ActiveDocument.Tables(1).Cell(1, 2).Range.Text
Name_1 = Left(Name_1, Len(Name_1)-2)