VBA Make link active in Lotus notes

Katy Jordan

Well-known Member
Joined
Jun 28, 2008
Messages
596
Hi, does anyone know how i can make the following link active in Lotus Notes, the cell has a named range Link. I have a code that works, i.e sends email via VBA but i want to make the file path active so the user can click and open the folder.

C:\Test/2011
 
Did you test this on your system? Also when the email is sent what will be the the link the that will be shown , i am confused on the HTML part as you have few file paths there.


The easiest way is to create a HTML MIME email, like this:
Code:
Sub Send_HTML_Email()

    Const ENC_IDENTITY_8BIT = 1729

    'Send Lotus Notes email containing links to files on local computer
    
    Dim NSession As Object      'NotesSession
    Dim NDatabase As Object     'NotesDatabase
    Dim NStream As Object       'NotesStream
    Dim NDoc As Object          'NotesDocument
    Dim NMIMEBody As Object     'NotesMIMEEntity
    Dim SendTo As String
    Dim subject As String
    Dim HTML As String, HTMLbody As String
    
    SendTo = "your.email@email.com, another.email@email.com"
    subject = Now & " Lotus Notes HTML MIME email"
    Debug.Print subject
    
    Set NSession = CreateObject("Notes.NotesSession")       'using Lotus Notes Automation Classes (OLE)
    Set NDatabase = NSession.GetDatabase("", "")
    
    If Not NDatabase.IsOpen Then NDatabase.OPENMAIL
    
    Set NStream = NSession.CreateStream
            
    HTMLbody = "< p>Links to files on local computer:< /p>" & _
        "< a href='file:///f:\temp\excel\test.csv'>test.csv< />< br>" & _
        "< a href='file:///f:\temp\excel'>Excel folder< />"
    
    HTML = "< html>" & vbLf & _
            "< head>" & vbLf & _
            "< meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"" />" & vbLf & _
            "< /head>" & vbLf & _
            "< body>" & vbLf & _
            HTMLbody & _
            "< /body>" & vbLf & _
            "< /html>"
    
    NSession.ConvertMime = False     'Don't convert MIME to rich text
    
    Set NDoc = NDatabase.CreateDocument()
    
    With NDoc
        .Form = "Memo"
        .subject = subject
        .SendTo = Split(SendTo, ",")
        
        Set NMIMEBody = .CreateMIMEEntity
        NStream.WriteText HTML
        NMIMEBody.SetContentFromText NStream, "text/html; charset=UTF-8", ENC_IDENTITY_8BIT
    
        .Send False
        .Save True, False, False
    End With
    
    NSession.ConvertMime = True      'Restore conversion
       
    Set NDoc = Nothing
    Set NSession = Nothing
   
End Sub
NOTE: To prevent the forum rendering the HTML in the code, I've had to add a space in each opening and closing tag, for example < p> < />. You will have to remove these spaces in your code so that the HTML is constructed correctly.
 
Upvote 0
Yes, I tested it and it works on my system.

There are 2 links. The text shown for the links are "test.csv" and "Excel folder".

Remember, as previously mentioned you have to remove the space in each HTML tag, otherwise the HTML will be improperly formed and the links probably won't show.
 
Upvote 0
Yes, I tested it and it works on my system.

There are 2 links. The text shown for the links are "test.csv" and "Excel folder".

Remember, as previously mentioned you have to remove the space in each HTML tag, otherwise the HTML will be improperly formed and the links probably won't show.

How does the code no where to put the links in the text body? For example if i have my Email Text like this, how does the code know to put the link after my text?


"Hi

The the Rec report has been completed and saved down as per below file path, please click the link.

File path

Regards

Katy"

When you run the code will the link appear as one line to allow the user to click on it
 
Upvote 0
Yes, I tested it and it works on my system.

There are 2 links. The text shown for the links are "test.csv" and "Excel folder".

Remember, as previously mentioned you have to remove the space in each HTML tag, otherwise the HTML will be improperly formed and the links probably won't show.

John did you manage to look at my issue above?

With email address rather than me physically typing them out in code i have a few email address in Sheets("Emailaddy") Col A, Row 6 onwards, how would i reflect this in code?
 
Upvote 0
Have you run the code? If so, compare the email it generates with the code and it should be obvious how the email text body is generated and where the links are put. The only changes you need to make for the code to run and send an email are to change the SendTo address(es) (in the SendTo variable) and remove spaces from the HTML tags. Yes, the local file links (URLs) will probably be incorrect for your computer, but are still valid as a proof of concept.

If you are still unsure, the HTMLbody variable holds the text of the email body, with paragraph tags (< p>) for each text paragraph and anchor tags (< a>) for the links. This variable is then concatenated to the HTML variable between the body opening and closing tags (< body> and < /body>). Therefore you would need to change the HTMLbody string for your particular email text.

To use email addresses from a range of cells, for example A1:A3 on Sheet1, change:

change:

.SendTo = Split(SendTo, ",")

to:

.SendTo = Sheets("Sheet1").Range("A1:A3").Value
 
Upvote 0
Ok i ran the code and i did not get any errors, which is good, but the body of my email text is on a excel spreadsheet, say for example sheet(3) ColA8:A33, how do i get the code to pick up this body text from excel?


Have you run the code? If so, compare the email it generates with the code and it should be obvious how the email text body is generated and where the links are put. The only changes you need to make for the code to run and send an email are to change the SendTo address(es) (in the SendTo variable) and remove spaces from the HTML tags. Yes, the local file links (URLs) will probably be incorrect for your computer, but are still valid as a proof of concept.

If you are still unsure, the HTMLbody variable holds the text of the email body, with paragraph tags (< p>) for each text paragraph and anchor tags (< a>) for the links. This variable is then concatenated to the HTML variable between the body opening and closing tags (< body> and < /body>). Therefore you would need to change the HTMLbody string for your particular email text.

To use email addresses from a range of cells, for example A1:A3 on Sheet1, change:

change:

.SendTo = Split(SendTo, ",")

to:

.SendTo = Sheets("Sheet1").Range("A1:A3").Value
 
Upvote 0
John, i can get the code to work, but how do i get the body text from Excel as specified above? This is the trick part. I do not want to hard code Body text.



Have you run the code? If so, compare the email it generates with the code and it should be obvious how the email text body is generated and where the links are put. The only changes you need to make for the code to run and send an email are to change the SendTo address(es) (in the SendTo variable) and remove spaces from the HTML tags. Yes, the local file links (URLs) will probably be incorrect for your computer, but are still valid as a proof of concept.

If you are still unsure, the HTMLbody variable holds the text of the email body, with paragraph tags (< p>) for each text paragraph and anchor tags (< a>) for the links. This variable is then concatenated to the HTML variable between the body opening and closing tags (< body> and < /body>). Therefore you would need to change the HTMLbody string for your particular email text.

To use email addresses from a range of cells, for example A1:A3 on Sheet1, change:

change:

.SendTo = Split(SendTo, ",")

to:

.SendTo = Sheets("Sheet1").Range("A1:A3").Value
 
Upvote 0
If anyone else that has lotus notes could you please advice how i would I get code to look at body text from Excel, i have managed to get it to work via hard coding, but i dont want to hard code body text.
 
Upvote 0
Similar to the way I showed you for the email addresses. For example, if the text is in cell A4 on Sheet1, change:

Code:
    HTMLbody = "< p>Links to files on local computer:< /p>" & _
        "< a href='file:///f:\temp\excel\test.csv'>test.csv< />< br>" & _
        "< a href='file:///f:\temp\excel'>Excel folder< />"
to:
Code:
    HTMLbody = "< p>" & Sheets("Sheet1").Range("A4").Text & "< /p>" & _
        "< a href='file:///f:\temp\excel\test.csv'>test.csv< />< br>" & _
        "< a href='file:///f:\temp\excel'>Excel folder< />"
Put each paragraph of text between a paragraph opening tag (< p>) and its closing tag (< /p>) in the HTML code - see http://www.w3schools.com/tags/tag_p.asp. The < br> tag is a line break - see http://www.w3schools.com/tags/tag_br.asp
 
Upvote 0

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