Guilherme Matheus
Guilherme Matheus

Reputation: 595

How to classify e-mail in Outlook before sending from Excel

I've got a macro in Excel that send e-mail through Outlook and it works perfectly. But in my company they recently added an e-mail classification. Can I insert on my code?

Example: If send 2.000 e-mails at once, I'll have to click 2.000 times on any of the classification button.

The language is in Portuguese (Brazil), so by order is: Confidential, Reserved, Internal, Public.

Classification:

Example of Classification

    Sub ContatoAtivo()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Dim xTexto As String
    Dim Texto As String
    Dim X, Y, Z As Integer
    Dim Email As String
    Dim Assunto As String
    Dim Qtd As Integer
    Dim rng As Range

    Qtd = Planilha2.ListObjects(1).DataBodyRange.Rows.Count

    For X = 1 To 1
        Email = Planilha2.Cells(X + 6, 8).Value
        Subject = Planilha3.Cells(11, 1).Value

        If Email <> "" Then

            Set rng = Nothing
            Set rng = Planilha3.Range("E12:F22").SpecialCells(xlCellTypeVisible)

            Set OutlookApp = CreateObject("Outlook.Application")
            Set OutlookMail = OutlookApp.CreateItem(0)

            Text = "Test"

            With OutlookMail
                .To = "test.test@test.com.br"
                .CC = ""
                .BCC = ""
                .Subject = Planilha3.Range("A5").Value & " | " & Subject
                .HTMLBody = Text
                '.Display
                .Send

            End With

            Set OutlookMail = Nothing
            Set OutlookApp = Nothing

            Texto = ""

        End If

    Next X

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

Thanks!

Upvotes: 0

Views: 2813

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

These controls belong to the Azure Information Protection add-in. Unfortunately, Office (nor VBA or VSTO) doesn't provide any trivial way for customizing a custom UI or dealing with it. Your options are listed below:

  1. Try to use the CommandBars.ExecuteMso method which executes the control identified by the idMso parameter. You must find the ID of controls you need to launch programmatically.
  2. Ask or find the command which is run by clicking the corresponding button in the UI. Note, you can use a late biding technology for that. So, you could call the method from VBA. Read more about that in the Walkthrough: Call code in a VSTO Add-in from VBA article.
  3. Use Microsoft Active Accessibility API. Microsoft Active Accessibility is a Component Object Model (COM)-based technology that improves the way accessibility aids work with applications running on Microsoft Windows. It provides dynamic-link libraries that are incorporated into the operating system as well as a COM interface and API elements that provide reliable methods for exposing information about UI elements.

Anyway, I'd suggest contacting AIP add-in developers.

Upvotes: 3

Related Questions