Solution: how to attach a Lotus Notes Doclink to an Outlook message

C

callmedoug

I meant to submit this a while back, oh well better late than never.

Anyway, when our company moved from Lotus Notes to Outlook, we needed a
way to still attach links to out database documents within the outlook
messages. The following code does that very thing. basically it takes
teh .ndl from your clipboard coverts it into a .txt file on your
system, attaches it to your email, then deletes itself.

I hope others can find value in this also.

regards
Doug

==== start code=====

Public Sub DocLink()

'---------------------------------------------------------------------------------------------------
' The DocLink macro was written by:
' Douglas Portz
' MTS Allstream
'
' This macro replicates the "doclink" function in Lotus Notes and
allows for Notes Doclinks to be
' attached in outlook
'
' To use this macro, you would create a doclink in notes, and then run
this macro in outlook to
'attach the link (actually attach macro to email (word macro) and build
a button within the email
'for convienece.)
'
' This macro requires the following additional library references to be
active
' - Microsoft Outlook 11.0 Object Library
' - Microsoft Forms 2.0 Object Library (auto added when a form is
added - delete form afterwards)
'----------------------------------------------------------------------------------------------------


' Stores the filename for the doclink
Dim strFileName As String
' create a clipboard item
Dim MyDataObj As New DataObject
' clipboard text item
Dim MyDocLink As Variant
' DocLink file and path
Dim MyLinkPath As String
'boolean check used for file name errors
Dim IsFileCreated As Boolean

'new file not yet created, no "kill" required
IsFileCreated = False

On Error GoTo ErrHdl

'copy the clipboard to dataobject
MyDataObj.GetFromClipboard
MyDocLink = MyDataObj.GetText

'Set file name as the first line of the DocLink
Dim x As Variant
x = Split(MyDocLink, Chr(10))
strFileName = Left(x(0), Len(x(0)) - 1)

' Open the file for exporting the link.
' file created in the Root Folder
MyLinkPath = "c:\" & strFileName & ".ndl"

TryAgain:
Open MyLinkPath For Output As #1

' file has been written to root, tag for deletion after attached
IsFileCreated = True

'check to ensure clipboard has something in it
If MyDocLink = "" Then
GoTo ErrHdl
End If

' check to see if this is a NDL link
If Left(x(1), 5) <> "<NDL>" Then
GoTo ErrHdl
Else
Print #1, MyDocLink
End If

'close the ndl file
Close #1

'add attached doclink
Set EmailMessage = Outlook.ActiveInspector.CurrentItem
With EmailMessage
.Attachments.Add (MyLinkPath)
End With

'delete the DocLink file from the hardrive
Kill (MyLinkPath)

Exit Sub

'Error Handling, if the file is not formated correctly notify user and
delete
ErrHdl:
Close #1

'if file was already created then remove it from harddrive
If IsFileCreated = True Then
Kill (MyLinkPath)
Else
' error may be because of the file name, use default and try again
MyLinkPath = "C:\DocLink.ndl"
GoTo TryAgain
End If

'Houston we have a problem - tell user the link can't be created
MsgBox "This does not appear to be a valid doclink", vbOKOnly, "Error"

End Sub

====end code====
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top