none
Visual Studio 2015 Outlook Add-in RRS feed

  • Question

  • Heyho,

    i´m realy new to VB and VS, i normally work with Java/JS but my Company wants a Add-In for Outlook 2010. So i got VS 2010 Ultimate and VS 2015 Community Edition with the VSTO Add-On and try my best.

    The add-in that is needed is a button to save a selected mail by one click in e.g. "documents". Found this code online. As you maybe can see, i created a button with the Ribbondesigner and tryed to add the code on it. The problem is that i get one error noone else got. Its says'ActiveExplorer' is not declared. It may be inaccessible due to its protection level.

    I hope someone can help me.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
    
        Dim oMail As Outlook.MailItem
        Dim objItem As Object
        Dim sPath As String
        Dim dtDate As Date
        Dim sName As String
        Dim enviro As String
        enviro = CStr(Environ("USERPROFILE"))
        For Each objItem In ActiveExplorer.Selection
            oMail = objItem
            sName = oMail.Subject
            ReplaceCharsForFileName(sName, "_")
            dtDate = oMail.ReceivedTime
            sName = Format(dtDate, "yyyy-mm-dd", vbUseSystemDayOfWeek, _
            vbUseSystem) & Format(dtDate, "-hh:nn:ss", _
            vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"
            sPath = enviro & "\Documents\"
            Debug.Print(sPath & sName)
            oMail.SaveAs(sPath & sName, olMSG)
        Next
    
    End Sub
    
    
    Private Sub ReplaceCharsForFileName(ByVal sName As String, _
    ByVal sChr As String _
    )
        sName = Replace(sName, "/", sChr)
        sName = Replace(sName, "\", sChr)
        sName = Replace(sName, ":", sChr)
        sName = Replace(sName, "?", sChr)
        sName = Replace(sName, Chr(34), sChr)
        sName = Replace(sName, "<", sChr)
        sName = Replace(sName, ">", sChr)
        sName = Replace(sName, "|", sChr)
    End Sub

    Thursday, October 15, 2015 8:25 AM

Answers

  • >>>The problem is that i get one error noone else got. Its says'ActiveExplorer' is not declared. It may be inaccessible due to its protection level.

    According to your description, I have made a smaple with your providing code, I can reproduce your issue and get a lot of grammar errors.

    So you need modify your codes to refer to below code:

    Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
    
    
        Dim currExplorer As Outlook.Explorer
    
        currExplorer = Globals.ThisAddIn.Application.ActiveExplorer()
    
        Dim oMail As Outlook.MailItem
    
        Dim objItem As Object
    
        If currExplorer IsNot Nothing Then
    
            For Each objItem In currExplorer.Selection
    
                oMail = objItem
    
                oMail = objItem
    
                oMail.SaveAs("D:\estmail.msg", Outlook.OlSaveAsType.olMSG)
    
            Next
    
        End If
    
    End Sub
    

    For more information, click here to refer about Walkthrough: Creating Your First VSTO Add-In for Outlook

    Friday, October 16, 2015 8:36 AM