2016-10-09 1 views
0

Word에서 활성 문서를 @ yahoo.com으로 검색하고 모든 인스턴스를 [email protected]으로 바꾸고 싶습니다. 나는 *@yahoo.com를 사용하는 경우는 명령에서 @ yahoo.comWord VBA에서 전자 메일 주소를 변경하고 싶습니다.

Sub kiffin() 
     With Selection.Find 
     .ClearFormatting 
     .MatchWildcards = True 
     .Text = "*@yahoo.com" 
     .Replacement.ClearFormatting 
     .Replacement.Text = "[email protected]" 
     .Execute Replace:=wdReplaceAll, Forward:=True, _ 
      Wrap:=wdFindContinue 
     End With 

    End Sub 

답변

0

* 명확이 경우 너무 욕심이 와일드 카드, 그리고 제한된 와일드 카드/정규식 전에 문서를 모두 지 웁니다 교체 찾을 수 Word의 찾기 기능에서 사용할 수있는 지원은 개별 전자 메일 주소를 식별하는 데 적합하지 않을 수 있습니다. (참고 : Word 나 RegEx는 내 전문 지식이 아닙니다.)

Word 문서의 전자 메일 주소가 하이퍼 링크로 제공되는 경우 Hyperlinks 컬렉션을 반복하고 "@yahoo.com" 도메인의 경우 TextToDisplay을 확인하면됩니다.

Sub ReplaceEmailHyperlinks() 

Dim newemail as String 
Dim h As Hyperlink 

newemail = "[email protected]" 

For Each h In ActiveDocument.Hyperlinks 
    If h.TextToDisplay Like "*@yahoo.com" Then 
     h.TextToDisplay = newemail 
     h.Address = "mailto:" & newemail 
    End If 
Next 
End Sub 
+0

감사합니다. – user6945490