2016-04-13 2 views
-1

私は次のコードで、 'pm'を含む文をドキュメント内で検索します - 見つかった場合は値をマスタードキュメントテーブル2に置き換えます細胞2,2。テーブルセル値= .... THEN(動作していない場合)

何らかの理由で、IF文が機能しないため、ドキュメント内のテキストを置き換えないと常にELSEに移動します。これは私が午前中立ち往生しているため、これを手伝うことができます。黒を削除

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

あなたは 'timeon'は、その点が含まれているかどうか確認することができませんか? – GSerg

+0

Timeonには、指定されたセル内の値が含まれます(直接ウィンドウをチェックするとき)。それの隣に黒い丸があります - それはそれに影響します、もしそうなら、私はどのようにテーブルから取り除きますか? – Tom36

+0

これは改行の後に表のセルターミネータ文字を続けたものです。比較する前に削除することをお勧めします。 – GSerg

答えて

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 
関連する問題