我有以下代码在文档中查找带有'pm'的句子 - 如果发现它替换它的值是主文档表2单元格2,2。
由于某种原因,IF语句不起作用并且总是去ELSE IF而不是替换文档中的文本 - 任何人都可以帮助我,因为我整个上午都被困住了。
timeon = wdDocSrc.Tables(2).Cell(2, 2).Range.Text
If timeon = "a" Then 'ERROR HERE
TimeReplace = wdDocSrc.Tables(2).Cell(3, 1)
TimeText = TimeReplace
wdDocTgt.Activate
With wdDocTgt
Selection.Find.Execute FindText:="pm", Forward:=True
If Selection.Text = "pm" Then
With Selection
' Collapse current selection to insertion point.
.Collapse
' Turn extend mode on.
.Extend
' Extend selection to word.
.Extend
' Extend selection to sentence.
.Extend
End With
With Selection
'Selection.Text = "We are now open Christmas DAY!!. "
Selection.Text = TimeText
End With
Else
MsgBox "No timing in this letter"
End If
End With
Else
MsgBox "ERROR" 'AWAYS JUMPS TO THIS
End If
答案 0 :(得分:0)
删除黑色确实有效 - 使用此代码:
timeon = wdDocSrc.Tables(3).Cell(2, 2)
Timeconfig = timeon
Timeconfig = Left$(Timeconfig, Len(Timeconfig) - 2)
If Timeconfig = "Yes" Then
TimeReplace = wdDocSrc.Tables(2).Cell(2, 1)
TimeText = TimeReplace