Error on HTMLBody Range

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hello, good afternoon, please can you help me with the code below it is coming up as an error when i click my email button, the code is this part 'RangetoHTML' from the first line below , hope you can help me please.

HTML:
aEmail.HTMLBody = StrBody & RangetoHTML(rngDataToEmail) & StrThanks

This is the whole code below:

HTML:
Private Sub CommandButton1_Click()

    Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
    
    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
    Dim StrBody As String
    
    Set aOutlook = CreateObject("Outlook.Application")
    Set aEmail = aOutlook.CreateItem(0)
    
LastRow = Sheets("Filter").Columns("B:K").Cells.Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Set rngDataToEmail = Sheets("Filter").Range("B10:K" & LastRow).SpecialCells(xlCellTypeVisible)
 
    
    ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED
    
    aEmail.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, (ulFlags)
    


          StrBody = "******>" & _
                            "Hi " & Me.TextBox35.Value & "
" & _
                            "" & Me.TextBox33.Value & "
" & _
                            "" & Me.TextBox17.Value & "
" & _
                            "" & _
                "" & _
                            "" & _
                            "" & _
                            "" & _
                            "" & _
                            "" & _
                "" & _
                            "" & _
                            "" & _
                            "" & _
                            "" & _
                            "" & _
                            "Date:" & Me.TextBox18.Text & "" & Me.TextBox19.Text & "" & Me.TextBox21.Text & "" & Me.TextBox23.Text & "" & Me.TextBox25.Text & "" & Me.TextBox26.Text & "Area:" & Me.TextBox9.Value & "" & Me.TextBox20.Value & "" & Me.TextBox22.Value & "" & Me.TextBox24.Value & "" & Me.TextBox29.Value & "" & Me.TextBox30.Value & "" & _
                            ""
                            



 
StrThanks = "******>" & _
                "


" & _
                "Many Thanks
" & _
                "Complex Team
" & _
                ""


        aEmail.Recipients.Add (UserForm1.TextBox36.Value)
        aEmail.CC = (UserForm1.TextBox37.Value)
        aEmail.BCC = ""
        aEmail.Subject = "Weekly " & Range("D2").Value & (UserForm1.TextBox39.Value)
        aEmail.HTMLBody = StrBody & RangetoHTML(rngDataToEmail) & StrThanks
        aEmail.Display
Unload Me

End Sub
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
hi it says 'Compile error. Sub or Function not defined. thanks for looking and hope you can help please.
 
Upvote 0
RangetoHTML isn't defined anywhere so it has no idea what to do with that part, which is why it's telling you Sub or Function not defined. I had no idea what this was supposed to do so I did a quick google search on this and saw someone who had a similar issue that you are having. You don't have
Code:
Function RangetoHTML(rng As Range)
anywhere. In the same search, I came up with this https://www.rondebruin.nl/win/s1/outlook/bmail2.htm. These should help.
 
Upvote 0
thank you where do i add the code you provided? sorry i am still new to aall of this
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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
Back
Top