Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA In XL Calling Notes and Putting Doclink in Message Body 1

Status
Not open for further replies.

gkinghrn

IS-IT--Management
May 12, 2004
6
GB
Here's the code I have to create the mail..but I want to Any idea how to include a doclink from Notes ..

The szMsg contains some basic text for the body of the email but I want to add a doclink into that body..any idea's?

Sub ComposeEmail(szBudgH As String, szSubj As String, szMsg As String)
On Error GoTo CEErr

Set doc = db.CREATEDOCUMENT
Call doc.REPLACEITEMVALUE("From", szSender)
If itisatest = "Y" Then
szbudgetH = "Gordon Kinghorn/acg/uk/aon"
End If
Call doc.REPLACEITEMVALUE("SendTo", szBudgH + szcanon)
If szBudgH = "Rachel Saunders" Then
Call doc.REPLACEITEMVALUE("SendTo", szBudgH + "/ARS/UK/AON")
End If
Rem Call doc.REPLACEITEMVALUE("CopyTo", szSenderNotesName)
Call doc.REPLACEITEMVALUE("Subject", szSubj)
Call doc.REPLACEITEMVALUE("Body", szMsg)
Call doc.SEND(False)
Exit Sub
CEErr:
MsgBox "There has been a problem sending mail to " + szBudgH, vbInformation
Resume Next
End Sub
 
I would think you could either just append it to the end of szMsg:
Code:
LinkText = "C:\My Documents\SomeFile.xls"
szMsg = szMsg & LinkText
or write some code to spot a "marker" string (like "LinkLocation") in szMsg and replace it with LinkText.

VBAjedi [swords]
 
If it was as simple..but the doclink is actually a Notes object I guess.. otherwise I could do as you say.. Not sure quite how it could be put into it if it was just a text string...I'll check that though..
 
gkinghrn
Please post if you find a solution as I would be very interested in using your solution.

Thanks,

Fred
 
Hiya,

to add a doclink you'll need to create a new NotesRichTextItem, and use its AppendDocLink method (assuming l_dbNotesDatabase points to your Notes DB and assuming l_docDocToLinkTo is set to the document you want to link to):

Code:
    Set l_docDocument = New NotesDocument(l_dbNotesDatabase)
    'Create RichTextItem
    Set l_rtxDoc = New NotesRichTextItem(l_docDocument, "DocLinkItem")
    'Add DocLink
    l_rtxDoc.AppendDocLink(l_docDocToLinkTo, "DocLinkName")


Also, take a look at the following site: there's a copy of the Lotus Notes VBRedbook: VERY handy

HTH

Cheers
Nikki
[bat] Look, mommy, I'm flying!
 
Trying to use this but failing on a couple of basic items I guess...
1. szmessage in my code is a big chunk of text that replaces the Body of the Notes form. I need that big chunk to contain the doclink

Do I put something like szmsg=szmmsg+l_rtxDoc.AppendDocLink(l_docDocToLinkTo, "DocLinkName")
then?
How do I get the doclink name though?

Sorry to be so bad...I'm an old programmer who needs to get more up-to-date I kniow!
 
Hiya,

apologies for not answering earlier: it's silly season with Bank Holidays over here ...

I've adapted your Sub slightly & tested it on out LoNo PCs. Using LoNo R5.0.8 but dunno whether any patches or whatnots have been installed (I'm just a programmer & not very admin-minded)
The code assigns the doc I want to link to to a LoNo Document object, creates a new LoNoDocument, adds a RichTextItem to this Document, adds the message body to the RichTextItem, & finally adds the doclink to the RichTextItem

Code:
Sub ComposeEmail(szBudgH As String, szSubj As String, szMsg As String, szSender As String)
    Dim l_notSession As NotesSession
    Dim l_notDb As NotesDatabase
    Dim l_notDocument As NotesDocument
    Dim l_notRichTextItem As NotesRichTextItem
    Dim l_notDocToLinkTo As NotesDocument
    
    On Error GoTo CEErr
    Set l_notSession = CreateObject("Notes.NotesSession")
    Set l_notDb = l_notSession.GetDatabase("", "")
    'Open mail
    l_notDb.OPENMAIL
    
    'Create new email message
    Set l_notDocument = l_notDb.CreateDocument
    'Just as a test: set the document to be linked to to the last doc in database
    'Change this to reflect the doc you want to link to
    Set l_notDocToLinkTo = l_notDb.AllDocuments.GetLastDocument
    
    With l_notDocument
        .AppendItemValue "From", szSender
        .AppendItemValue "SendTo", szBudgH
        If szBudgH = "Rachel Saunders" Then .AppendItemValue "SendTo", szBudgH
        .AppendItemValue "Subject", szSubj
        'Now for the RichTextItem: I've changed the format of the command to have it more in line with the other code
        Set l_notRichTextItem = .CreateRichTextItem("Link")
        l_notRichTextItem.AppendText szMsg
        If Not (l_notDocToLinkTo Is Nothing) Then
            l_notRichTextItem.AddNewLine 2
            l_notRichTextItem.AppendDocLink l_notDocToLinkTo, "Double-click to open document"
        End If
        .savesentmail
        .Send False
    End With
    
    'Release objects
    Set l_notDocument = Nothing
    Set l_notDocToLinkTo = Nothing
    Set l_notRichTextItem = Nothing
    Set l_notDb = Nothing
    Set l_notSession = Nothing
    
    Exit Sub
CEErr:
    'MsgBox "There has been a problem sending mail to " + szBudgH, vbInformation
    MsgBox Err.Description & " (" & Err.Number & ")"
    
    'Release objects
    Set l_notDocument = Nothing
    Set l_notDocToLinkTo = Nothing
    Set l_notRichTextItem = Nothing
    Set l_notDb = Nothing
    Set l_notSession = Nothing
    Exit Sub
    Resume
End Sub

HTH

Cheers
Nikki
[bat] Look, mommy, I'm flying!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top