2017-02-27 57 views
-2

我有一個報告,可以是從5到數百頁,提供基於實驗室測試的患者信息的任何地方。每個患者記錄最後用複選框分隔下劃線。 「___________ | ____ |」例如:vba do while循環中的多個條件

姓氏,第一個患者數量單位ANC 02 #### 2/23/2017 15:56 BLOOD GLU-ANC 416 mg/dL H * REf。反應:60-100臨界50-399 評論:患者的詳細信息和醫生的筆記在這裏顯示 ,並且可以非常靈活... 更多臨牀信息等 _________________________________________________________________________ | ____ | 姓氏,第一個患者編號單位CH 1234 2/23/2017 15:56 SERUM TROP I 54 mg/dL H * REf。反應:60-100臨界50-399 評論:患者的詳細信息和醫生的筆記在這裏顯示 ,並且可以非常靈活... 更多臨牀信息等 _________________________________________________________________________ | ____ | 姓氏,第一個患者數量單位ANC 1234 2/23/2017 15:56 FECES FIT正性H * REf。範圍:「NEG」 - 「」 60-100關鍵:報告 點評:從醫生與患者的詳細信息和注意事項顯示 這裏可以非常靈活...... 更多臨牀信息等 _________________________________________________________________________ | ____ |

如果我在患者記錄中找到某個值(例如ANC或FIT),則可以在查看打印報告時跳過這些記錄。所以我想用| SKIP |替換下劃線複選框。

我可以很容易地做到這一點,爲下一個循環,但問題是我不知道有多少「動脈血液」或「ANC」或「FECES FIT」,將出現在給定的報告。所以我一直試圖弄清楚如何用Do While Selection.Find.Execute = True語句替換我的For Next循環。

但嘗試了很多變化,無法獲得正確的語法。 任何幫助將不勝感激!

這是我的工作Next循環

Sub xSimplefind() 
Dim vtext As String 
    vtext = InputBox("Text to find") 'Here I enter 1st search value ie. "ANC" 
    For i = 1 To 7 
    With Selection.Find 
    .Execute FindText:=vtext 
    Selection.MoveRight Unit:=wdCharacter, Count:=1 
End With 
'Once I find that first item, I then look for the very next "|_____|" 
    With Selection.Find 
    .Execute FindText:="|____|" 'TypeText overwrites Selected text. 
    Selection.TypeText Text:="|SKIP|" 
End With 
Next i 
End Sub 

回答

0

這不正是你所需要的,但一個例子希望設置你在正確的軌道上:

Option Explicit 

Sub MultiFind() 
    Dim valueToSkip() As String 
    valueToSkip = Split("ANC,FIT,ARTERIAL BLOOD,FECES FIT", Delimiter:=",") 

    Dim found As Boolean 
    Dim value As Variant 
    Dim result As Variant 

    found = False 
    For Each value In valueToSkip 
     With Selection.Find 
      Set result = .Execute(FindText:=value) 
      If Not result Is Nothing Then 
       found = True 
       Exit For 
      End If 
     End With 
    Next value 

    If found Then 
     '--- add |SKIP| here 
    End If 

End Sub 
+0

感謝您的快速響應!!我嘗試了我的粘貼版本的代碼,但是系統在「Set result = .Execute(FindText:= value)」行停止,我嘗試了許多變化,似乎無法通過該點。幫助將不勝感激。 – KenGooch

0

此代碼的工作,如果任何人都需要做這樣的事情...... 感謝您的幫助和輸入!子測試() Dim vtext As Variant 對於數組中的每個vtext(「動脈」,「ANC」,「FIT」,「PREVIOUS」)) Selection.HomeKey單位:= wdStory

 ' 
    'Inner loop to check every line 
    ' 
    While True 
     Selection.Find.ClearFormatting 
     Selection.Find.Replacement.ClearFormatting 
     With Selection.Find 
      .Text = vtext 
      .Replacement.Text = "" 
      .Forward = True 
      .Wrap = wdFindContinue 
      .Format = False 
      .MatchCase = False 
      .MatchWholeWord = False 
      .MatchWildcards = False 
      .MatchSoundsLike = False 
      .MatchAllWordForms = False 
     End With 
     Selection.Find.Execute 
     With Selection.Find 
      .Text = "|" 
      .Replacement.Text = "" 
      .Forward = True 
      .Wrap = wdFindContinue 
      .Format = False 
      .MatchCase = False 
      .MatchWholeWord = False 
      .MatchWildcards = False 
      .MatchSoundsLike = False 
      .MatchAllWordForms = False 
     End With 
     Selection.Find.Execute 
     Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend 
     If Selection.Text <> "|SKIP|" Then 
      Selection.Text = "|SKIP|" 
     Else 
      GoTo DoNextWord 
     End If 
    Wend 

DoNextWord: 接着vtext 結束子