Assistance changing VBA code to display as HTML or picture of a selection in Lotus Notes

jularobert

New Member
Joined
Nov 26, 2013
Messages
11
Hello All.

I have a workbook that sends a copy via Lotus Notes. The body of the e-mail is text from the excel workbook. Unfortunately it does not look good and I would like to change the code to paste either as HTML, Jpeg or some option to make it readable for recipients without the need to open the excel attachment.

Here is my code:

Appreciate any and all help.

VBA Code:
Sub SendActiveSheet()



    Dim stFileName As String

    Dim vaRecipients As Variant

    Dim noSession As Object

    Dim noDatabase As Object

    Dim noDocument As Object

    Dim noEmbedObject As Object

    Dim noAttachment As Object

    Dim stAttachment As String

    Dim EMBED_ATTACHMENT As Long

    Dim bodytext As String

    Dim vaCopyTo As Variant

    Dim myArr As Variant

    Dim emailto As Variant

    Dim wb1 As Workbook, wb2 As Workbook

    Dim stSubject As String

    Dim vDay As Integer

    Dim rng As Range

    Dim cell As Range

    Dim rngText As String

  

    ' Confirmation before sending

    If MsgBox("Are you sure you want to send this report?", vbOKCancel) = vbCancel Then Exit Sub

  

    Application.DisplayAlerts = False

  

    ActiveWorkbook.Unprotect Password:=PW

  

    Select Case ActiveSheet.Range("N15").Value

        ' Match the day value

        Case 1 To 20

            vDay = ActiveSheet.Range("N15").Value

        Case Else

            vDay = 0

    End Select

      

    EMBED_ATTACHMENT = 1454

  

    ' Define the range to copy (adjust the range as needed)

    Set rng = ActiveSheet.Range("A1:U20")

  

    ' Convert the range to text by looping through each cell

    rngText = ""

    For Each cell In rng

        rngText = rngText & cell.Value & vbTab

        If cell.Column = rng.Columns.Count Then

            rngText = rngText & vbNewLine

        End If

    Next cell




    ' Prepare email body with the range text

    bodytext = "Good Morning," & vbNewLine & vbNewLine

    bodytext = bodytext & "Attached above is the  report from last night." & vbNewLine & vbNewLine

    bodytext = bodytext & "Below is a summary of the report:" & vbNewLine & vbNewLine

    bodytext = bodytext & rngText & vbNewLine & vbNewLine

    bodytext = bodytext & "Thanks," & vbNewLine

    bodytext = bodytext & "The C Team" & vbNewLine & vbNewLine

    bodytext = bodytext & "This is a system generated email."

      

    Set wb1 = ThisWorkbook

    stSubject = "Daily Report - Day " & vDay




    ' Copy the active sheet to a new temporary workbook.

    With ActiveSheet

        .Copy

        stFileName = "Daily  Report.xlsm"

    End With

  

    stAttachment = stPath & stFileName

  

    ' Save and close the temporary workbook.

    Set wb2 = ActiveWorkbook

    wb2.ActiveSheet.Unprotect Password:=PW

  

     With wb1.ActiveSheet
        .Unprotect Password:=PW
        .Range("A1:U200").Copy Destination:=wb2.ActiveSheet.Range("A1")
        .Protect Password:=PW, _
        DrawingObjects:=True, _
        Contents:=True, _
        Scenarios:=True, _
        AllowFormattingCells:=True, _
        AllowFormattingColumns:=True, _
        AllowFormattingRows:=True
        .EnableSelection = xlNoRestrictions
    End With

  

    With wb2

        .SaveAs stAttachment, FileFormat:=52

        .Close

    End With

 

    ' Create the list of recipients.

    Set emailto = Worksheets("Setup").Range("F13")

    Set myArr = Worksheets("Setup").Range("F15:F54")

  

    vaRecipients = emailto

    vaCopyTo = myArr

  

    ' Instantiate the Lotus Notes COM's Objects.

    Set noSession = CreateObject("Notes.NotesSession")

    Set noDatabase = noSession.GETDATABASE("", "")

  

    ' If Lotus Notes is not open then open the mail-part of it.

    If noDatabase.IsOpen = False Then noDatabase.OPENMAIL

  

    ' Create the e-mail and the attachment.

    Set noDocument = noDatabase.CREATEDOCUMENT

    Set noAttachment = noDocument.CREATERICHTEXTITEM("stAttachment")

    Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)

  

    ' Add values to the created e-mail main properties.

    With noDocument

        .Form = "Memo"

        .SendTo = vaRecipients

        .CopyTo = vaCopyTo

        .Subject = stSubject

        .Body = bodytext

        .SaveMessageOnSend = False

        .PostedDate = Now()

        .Send 0, vaRecipients

    End With

  

    ActiveWorkbook.Protect Structure:=True, Windows:=False, Password:=PW

  

    ' Delete the temporary workbook.

    Kill stAttachment

  

    ' Release objects from memory.

    Set noEmbedObject = Nothing

    Set noAttachment = Nothing

    Set noDocument = Nothing

    Set noDatabase = Nothing

    Set noSession = Nothing

  

    MsgBox "The Daily  Report has been successfully detached and e-mailed to the R", vbInformation




    Application.DisplayAlerts = True



End Sub
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
A few administrative issues ..

1. Reminder:
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Assistance changing VBA code to display as HTML or picture of a selection in Lotus Notes
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.


2. I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)


3. When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊
 
Upvote 0
A few administrative issues ..

1. Reminder:
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Assistance changing VBA code to display as HTML or picture of a selection in Lotus Notes
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.


2. I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)


3. When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊
Thank you so much
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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