Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA-替换word表格中的文本_Vba_Ms Word - Fatal编程技术网

VBA-替换word表格中的文本

VBA-替换word表格中的文本,vba,ms-word,Vba,Ms Word,我尝试将Word中的表格中的文本复制到文本中,但在文本被覆盖后,它会出现在文本“黑点”中。拜托,你能告诉我哪里错了吗 Dim rngStory As Range Name_1 = ActiveDocument.Tables(1).Cell(1, 2) For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "<&l

我尝试将Word中的表格中的文本复制到文本中,但在文本被覆盖后,它会出现在文本“黑点”中。拜托,你能告诉我哪里错了吗

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
Dim rngStory As范围
Name_1=ActiveDocument.Tables(1).单元格(1,2)
对于ActiveDocument.StoryRanges中的每个rngStory
和rngStory一起,找到
.Text=“”
.Replacement.Text=名称\u 1
.Wrap=wdFindContinue
.Execute Replace:=wdReplaceAll
以
下一站
试试:

Name_1 = Split(ActiveDocument.Tables(1).Cell(1, 2).Range.Text, vbCr)(0)
或者,如果单元格中可能有多个段落:

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

这是因为一个表单元包含两个在幕后负责内部单元结构的字符:一个Chr(13)和一个Chr(7)。需要从文本(
Name\u 1
)中“修剪”这些内容。请参阅:任何作品的可能重复。如果你得到了一个类型不匹配,那是因为你的代码中有其他错误。非常感谢你的帮助。