2015-01-23 3 views
0

Excel vba 응용 프로그램의이 하위 프로그램은 수년간 잘 작동하여 보내려는 전자 메일 (.Display)을 표시하기 전에 Outlook 서명을 전자 메일에 삽입했습니다. 이 기능은 Excel 2007의 XL 2007 및 Windows 7의 2013에서 작동합니다.Excel에서 vba를 사용하여 전자 메일 서명 삽입

이제 Windows 8.1 및 Office 2013을 사용하면 오류 루틴에 오류 91이 발생합니다. 참고 문헌 중 하나에 문제가 될 수 있습니까? - 또는 코드에서 약간의 변경이 필요합니까? 모든 도움을 기꺼이 받아 들였습니다! 오류 루틴을 사용하지 않는 디버깅 할 때

Sub InsertSig2007(strSigName As String) 

Dim objItem As Object 
Dim objInsp As Outlook.Inspector 
' requires a project reference to the 
' Microsoft Office library 
Dim objCBP As Office.CommandBarPopup 
Dim objCBP2 As Office.CommandBarPopup 
Dim objCBB As Office.CommandBarButton 
Dim colCBControls As Office.CommandBarControls 
Set objInsp = ActiveInspector 
If Not objInsp Is Nothing Then 
    Set objItem = objInsp.CurrentItem 
    If objItem.Class = olMail Then 
    ' get Insert menu 
     Set objCBP = objInsp.CommandBars.ActiveMenuBar.FindControl(, 30005) 
     ' get Signature submenu 
     Set objCBP2 = objCBP.CommandBar.FindControl(, 5608) 
     If Not objCBP2 Is Nothing Then 
      Set colCBControls = objCBP2.Controls 
      For Each objCBB In colCBControls 
      Debug.Print objCBB.Caption 
      If objCBB.Caption = strSigName Then 
       objCBB.Execute ' **** see remarks 
       Exit For 
      End If 
      Next 
     End If 
    End If 
End If 
Set objInsp = Nothing 
Set objItem = Nothing 
Set colCBControls = Nothing 
Set objCBB = Nothing 
Set objCBP = Nothing 
Set objCBP2 = Nothing 

최종 하위

+0

은 매우 부서지기 쉬운 보인다. 어떤 라인이 실패합니까? – Bathsheba

답변

0

"이 내 오류 루틴에서 오류 (91)와 함께 나온다." 그렇게하면 문제가있는 행을보고 질문에 무엇이 있는지 말할 수 있습니다.

Set objCBP = objInsp.CommandBars.ActiveMenuBar.FindControl(, 30005) 

CommandBars.FindControl Method (Office) 참조 아마도 "일부 Microsoft Office 응용 프로그램을 CommandBars의 사용은 Microsoft Office Fluent 사용자 인터페이스의 새로운 리본 구성 요소에 의해 대체되었습니다."

참고 : CommandBars.ExecuteMso Method (Office)은 2013 년에 작동하지만 서명 버튼을 사용할 수 없다고 생각합니다.

코드 대신 여기에 Insert Outlook Signature in mail 대체 코드가 있습니다. 가능성이 하나

:

Sub Mail_Outlook_With_Signature_Html_2() 
' Don't forget to copy the function GetBoiler in the module. 
' Working in Office 2000-2013 
    'Dim OutApp As Object 
    Dim OutMail As Object 
    Dim strbody As String 
    Dim SigString As String 
    Dim Signature As String 

    'Set OutApp = CreateObject("Outlook.Application") 
    'Set OutMail = OutApp.CreateItem(0) 

    Set OutMail = CreateItem(0) 

    strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _ 
       "Please visit this website to download the new version.<br>" & _ 
       "Let me know if you have problems.<br>" & _ 
       "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _ 
       "<br><br><B>Thank you</B>" 

    'Change only Mysig.htm to the name of your signature 
    SigString = Environ("appdata") & _ 
       "\Microsoft\Signatures\Mysig.htm" 

    If Dir(SigString) <> "" Then 
     Signature = GetBoiler(SigString) 
    Else 
     Signature = "" 
    End If 

    On Error Resume Next 

    With OutMail 
     '.To = "[email protected]" 
     .CC = "" 
     .BCC = "" 
     .Subject = "This is the Subject line" 
     .HTMLBody = strbody & "<br>" & Signature 
     '.Send  
     'or use 
     .Display 
    End With 

    On Error GoTo 0 
    Set OutMail = Nothing 
    'Set OutApp = Nothing 
End Sub 


Function GetBoiler(ByVal sFile As String) As String 
'Dick Kusleika 
    Dim fso As Object 
    Dim ts As Object 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2) 
    GetBoiler = ts.readall 
    ts.Close 
End Function 
관련 문제