2010-03-26 6 views
5

ItemSend에 코드를 삽입하고 ThisOutlookSession 모듈을 저장했습니다. 그것은 한 번 작동하고 더 이상 작동합니다. VBAproject.OTM으로 저장되었으며 Outlook을 다시 시작한 후에 모듈을 열 때 계속 남아 있습니다. 당신이 ItemSend 이벤트를 후킹하는 경우Outlook 2007의 ItemSend 이벤트에서 숨은 참조가 작동하지 않습니다.

Private Sub Application_ItemSend(ByVal Item As Object, _ 
           Cancel As Boolean) 
    Dim objRecip As Recipient 
    Dim strMsg As String 
    Dim res As Integer 
    Dim strBcc As String 
    On Error Resume Next 

    ''# #### USER OPTIONS #### 
    ''# address for Bcc -- must be SMTP address or resolvable 
    ''# to a name in the address book 
    strBcc = "[email protected]" 

    Set objRecip = Item.Recipients.Add(strBcc) 
    objRecip.Type = olBCC 
    If Not objRecip.Resolve Then 
     strMsg = "Could not resolve the Bcc recipient. " & _ 
       "Do you want still to send the message?" 
     res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _ 
       "Could Not Resolve Bcc Recipient") 
     If res = vbNo Then 
      Cancel = True 
     End If 
    End If 

    Set objRecip = Nothing 
End Sub 
+0

FWIW는 이메일 주소가 항상 해결되므로 해결 방법을 호출하거나 값을 확인할 필요가 없습니다. – JimmyPena

답변

2

, 그 클래스 WithEvents와 모듈과 일반 모듈을 호출하는 코드에 있어야합니다. 또한 메시지에 BCC가 계속 적용되도록 Item.Save을 수행하려고합니다. 항목의 제목 필드

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 

If Item.Subject = "exact match" Then 

    strBcc = "[email protected]" 

    Set objRecip = Item.Recipients.Add(strBcc) 
    objRecip.Type = olBCC 
    If Not objRecip.Resolve Then 
     strMsg = "Could not resolve the Bcc recipient. " & _ 
       "Do you want still to send the message?" 
     res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _ 
       "Could Not Resolve Bcc Recipient") 
     If res = vbNo Then 
      Cancel = True 
     End If 


    End If 
    Item.Save 

    Set objRecip = Nothing 


End If 

또는 사용에

3

사용 if 문 당신이 주제

If InStr(Item.Subject, "BCCSubject") = 0 Then 


End If 
0

나는 최근에이 문제를 가지고 있었다의 단어를 포함합니다. 그것은. pst 파일이 어떤 식 으로든 손상된 후 시작되었고 scanpst.exe를 실행해야했습니다 (오류 메시지가 어디에 있는지 알려주지 않기 때문에 드라이브를 검색해야합니다)

scanpst.exe를 실행 한 후 그리고 그 문제는 그 자체로 나타났습니다. 이것이 제가 고쳐 놓은 방법입니다.

먼저 매크로 보안으로 살펴 보았습니다. 나는 그것을 가장 낮은 설정으로했다. Here is a link that covers how to change macro security. 도구> 매크로> 보안으로 이동하십시오. "매크로 보안 검사 안 함"으로 설정했습니다.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 

Dim objRecip As Recipient 
Dim strMsg As String 
Dim res As Integer 
Dim strBcc As String 
On Error Resume Next 

' #### USER OPTIONS #### 
' address for Bcc -- must be SMTP address or resolvable 
' to a name in the address book 
strBcc = "PUT YOUR EMAIL ADDRESS HERE AND LEAVE THE QUOTES" 

Set objRecip = Item.Recipients.Add(strBcc) 
objRecip.Type = olBCC 
If Not objRecip.Resolve Then 
strMsg = "Could not resolve the Bcc recipient. " & _ 
"Do you want still to send the message?" 
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _ 
"Could Not Resolve Bcc Recipient") 
If res = vbNo Then 
Cancel = True 
End If 
End If 

Set objRecip = Nothing 

End Sub 

가 그럼 난 후 저장 버튼을 매크로를 실행하는 작은 녹색 재생 버튼을 클릭 :

은 그 때 나는이 정확한 코드를 사용했다. 그것은 매크로 이름을 물었다. bccUsername을 사용하고 create를 클릭했습니다. 편집자는 ThisOutLookSession 아래에 Modules이라는 섹션을 추가했습니다.

그런 다음 Outlook을 다시 시작하고 두 번 테스트 한 결과 작동했습니다.

내가 다시 한 번 작업을 시작하게 만들었지 만 단계와 너무 관련이 없으므로이 문제는 나와 다른 사람들이 같은 문제를 해결하는 데 도움이됩니다.