2013-12-17 4 views
0

단어로 붙여 넣은 두 사람의 긴 대화를 자동으로 자르려고합니다.단어로 시작하는 줄을 찾아서 삭제하십시오.

내가 짐 블루에서 모든 텍스트를 포맷 할

Jim , 18th November 05:23 

Hi! 

Sarah , 19th November 06:03 

Hello there 

입력하고 사라 빨간색의 모든 텍스트입니다. 나는이 과정을 수행 할 필요가 있다고 생각이 이렇게하기 위해서는 : 그것은 선에 도달 할 때까지 "짐"로 시작하는 행을 찾습니다

  1. 컬러
  2. 빨간색 텍스트의 모든 비트를과 파란색 후 모든 포맷을하는 "Sarah"로 시작합니다.
+0

당신이 VBA를 사용해야합니까 데 도움이? –

답변

2

희망이

Public Sub ColorMeRedBlue() 
    Selection.HomeKey Unit:=wdStory 

    color_the_text = False 

    For Each line_in_para In ActiveDocument.Paragraphs 

     text_in_line = line_in_para.Range.Text 
     check_name = Split(text_in_line, " ") 

     If InStr("Jim", check_name(0)) Then 
      color_the_text = False 
     ElseIf InStr("Sarah", check_name(0)) Then 
      color_the_text = True 
     End If 

     If color_the_text = False Then 
      Selection.HomeKey Unit:=wdLine 
      Selection.EndKey Unit:=wdLine, Extend:=wdExtend 
      Selection.Font.Color = wdColorRed 
      Selection.EndKey Unit:=wdLine, Extend:=wdExtend 
      Selection.EndKey Unit:=wdLine 
      Selection.MoveDown Unit:=wdLine, Count:=1 
     ElseIf color_the_text = True Then 
      Selection.HomeKey Unit:=wdLine 
      Selection.EndKey Unit:=wdLine, Extend:=wdExtend 
      Selection.Font.Color = wdColorBlue 
      Selection.EndKey Unit:=wdLine, Extend:=wdExtend 
      Selection.EndKey Unit:=wdLine 
      Selection.MoveDown Unit:=wdLine, Count:=1 
     End If 

    Next line_in_para 

End Sub 
관련 문제