G
Guest
Hi,
I wrote a marco that would allow me to create and attach a lotus notes
DocLink to my outlook mail message, while the code works fine as a
macro, it only works when the macro is part of the "Microsoft Outlook
Session" module. What I really want to do with this code is create a
macro button that resides on the mail message document itself.
I have tried opening a message and then creating a macro there (I think
the module is located in "Normal"
Anyway I get the following error when I run the code
"Variable not defined" and it points to the following line of code
Set EmailMessage = Outlook.ActiveInspector.CurrentItem
(highlighting the word Outlook)
I suspect that the message itself does not have access to all the same
procedures and functions as the Session does.
So here is my question, How can I add a command button to the Mail
Message toolbar that will run the following code? Where would I put
this code, and how do I link it to a command button in the mail
message?
Thanks
---------Code------------------------
Option Explicit
Public Sub DocLink()
' Stores the filename provide by the user
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
'Display the input box with the default 'Titles.Txt'
strFileName = InputBox("Enter a filename for DocLink", "Provide
filename...", "")
'Check if the user has pressed Cancel (Inputbox returns a zero length
string)
If strFileName = "" Then
Exit Sub
End If
' Open the file for exporting the link.
' file created in the Root Folder
MyLinkPath = "c:\" & strFileName & ".ndl"
Open MyLinkPath For Output As #1
'copy the clipboard to dataobject
MyDataObj.GetFromClipboard
MyDocLink = MyDataObj.GetText
Print #1, MyDocLink
'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)
End Sub
I wrote a marco that would allow me to create and attach a lotus notes
DocLink to my outlook mail message, while the code works fine as a
macro, it only works when the macro is part of the "Microsoft Outlook
Session" module. What I really want to do with this code is create a
macro button that resides on the mail message document itself.
I have tried opening a message and then creating a macro there (I think
the module is located in "Normal"
Anyway I get the following error when I run the code
"Variable not defined" and it points to the following line of code
Set EmailMessage = Outlook.ActiveInspector.CurrentItem
(highlighting the word Outlook)
I suspect that the message itself does not have access to all the same
procedures and functions as the Session does.
So here is my question, How can I add a command button to the Mail
Message toolbar that will run the following code? Where would I put
this code, and how do I link it to a command button in the mail
message?
Thanks
---------Code------------------------
Option Explicit
Public Sub DocLink()
' Stores the filename provide by the user
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
'Display the input box with the default 'Titles.Txt'
strFileName = InputBox("Enter a filename for DocLink", "Provide
filename...", "")
'Check if the user has pressed Cancel (Inputbox returns a zero length
string)
If strFileName = "" Then
Exit Sub
End If
' Open the file for exporting the link.
' file created in the Root Folder
MyLinkPath = "c:\" & strFileName & ".ndl"
Open MyLinkPath For Output As #1
'copy the clipboard to dataobject
MyDataObj.GetFromClipboard
MyDocLink = MyDataObj.GetText
Print #1, MyDocLink
'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)
End Sub