Email Encryption code vba

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,107
Hi good morning, hope you can help me please, i have the code below where i have put an encryption in for emails, but i am getting an error on the line below please can you help?

I get an eror on this line -
Code:
aEmail.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, (ulFlags)

VBA Code:
Private Sub CommandButton2_Click()
Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003%22"
Dim aOutlook As Object
Dim aEmail As Object
Dim ulFlags As Integer
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
Dim rngDataToEmail As Range

    Set aOutlook = CreateObject("Outlook.Application")
    Set aEmail = aOutlook.CreateItem(0)


 ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED

    aEmail.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, (ulFlags)

    With Sheets("Work Issue")
        Set rngDataToEmail = .Range("B1:R" & .Range("B" & Rows.Count).End(xlUp).Row)
    End With


    
aEmail.HTMLBody = "<html><body><p>Hi " & Me.TextBox9.Value & "</p>" _
                    & "<p>" & Me.ComboBox2.Value & "</p>" _
                    & "<p>" & Me.ComboBox3.Value & "</p>" _
                    & "<p>" & Me.TextBox1.Value & "</p>" & RangetoHTML(rngDataToEmail) _
                    & "<p>Many Thanks</p>" _
                    & "<p>Complex Team</p>" _
                    & "</body></html>"


    aEmail.Recipients.Add (UserForm1.TextBox2.Value)
    aEmail.CC = (UserForm1.TextBox3.Value)
    aEmail.BCC = ""
    aEmail.Subject = (UserForm1.TextBox6.Value) & (UserForm1.TextBox8.Value) & (UserForm1.ComboBox4.Value)
    aEmail.Display

    Unload Me


End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
39,363
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
The %22 on the end of the namespace identifier looks wrong to me.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
39,363
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
It would help if you said what the error actually is?
 

Forum statistics

Threads
1,176,507
Messages
5,903,450
Members
435,030
Latest member
zechariah

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top