Solved

Read receipt when Word document is opened

Posted on 2009-05-07
4
489 Views
Last Modified: 2012-05-06
Greetings!  How can I have a read receipt Emailed to me when a Word document is opened?  I'd like to have the user name, time, date etc.  Is there a way to do this within word or are there third party applications?  
0
Comment
Question by:thoban531
  • 3
4 Comments
 
LVL 17

Expert Comment

by:wobbled
ID: 24327111
You can do this by putting some code into the word document using the FileOpen command.  The only problem here is are the users internal (ie same company etc).  There are various was that you can do this, but not knowing their email client is going to be difficult to code for.  Also not all email clients will allow you to manipulate them outside of their application.

But to give you an idea

In the word document - add the following in the ThisDocument section of the VBA code


Option Explicit
 

Private Sub Document_Open()
 

Dim bodytext As String
 

    bodytext = Now() & vbLf

    bodytext = bodytext & "whatever else you want"

    

   Call SendNotesMail("subject", "", "me@this.com", bodytext, True)
 

End Sub
 

Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, bodytext As String, SaveIt As Boolean)
 

Dim Maildb As Object        'The mail database

Dim Username As String      'The current users notes name

Dim MailDbName As String    'The current users notes mail database name

Dim MailDoc As Object       'The mail document itself

Dim AttachME As Object      'The attachment richtextfile object

Dim Session As Object       'The notes session

Dim EmbedObj As Object      'The embedded object (Attachment)
 

On Error GoTo Err_SendNotesMail
 

    'Start a session to notes

    Set Session = CreateObject("Notes.NotesSession")
 

    'Next line only works with 5.x and above. Replace password with your password

    'Session.Initialize ("password")

    

    'Get the sessions username and then calculate the mail file name

    'You may or may not need this as for MailDBname with some systems you

    'can pass an empty string or using above password you can use other mailboxes.

    Username = Session.Username

    MailDbName = Left$(Username, 1) & Right$(Username, (Len(Username) - InStr(1, Username, " "))) & ".nsf"

    

    'Open the mail database in notes

    Set Maildb = Session.GetDatabase("", MailDbName)
 

     If Maildb.IsOpen = True Then

          'Already open for mail

     Else

         Maildb.OPENMAIL

     End If

     

    'Set up the new mail document

    Set MailDoc = Maildb.CreateDocument

        MailDoc.Form = "Memo"

        MailDoc.sendto = Recipient

        MailDoc.Subject = Subject

        MailDoc.body = bodytext

        MailDoc.SaveMessageOnSend = SaveIt

    

    'Set up the embedded object and attachment and attach it

    If Attachment <> "" Then

        Set AttachME = MailDoc.CreateRichTextItem("Attachment")

        Set EmbedObj = AttachME.EmbedObject(1454, "", Attachment, "Attachment")

        MailDoc.CreateRichTextItem ("Attachment")

    End If

    

    'Send the document

    MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder

    MailDoc.Send 0, Recipient

    

    'Clean Up

    Set Maildb = Nothing

    Set MailDoc = Nothing

    Set AttachME = Nothing

    Set Session = Nothing

    Set EmbedObj = Nothing

    Exit Sub
 

Err_SendNotesMail:

    Exit Sub
 

End Sub

Open in new window

0
 
LVL 17

Expert Comment

by:wobbled
ID: 24327135
The above was working on the principle that the user was using Lotus Notes as their email client.  If you are using outlook the just look at the Do.Cmd SendObject approach - much easier (a quick google will get you the code)
0
 

Author Comment

by:thoban531
ID: 24328946
Thanks for the reply wobbled.  All users will be internal and on the same network.  I'm using Outlook as the mail client.  I'm not seeing where the user name, time and date who actually opened the document is being collected and sent to Notes in the code example you sent. Do you have any examples of doing it with Outlook?  
0
 
LVL 17

Accepted Solution

by:
wobbled earned 50 total points
ID: 24395375
Sorry for the delay.  Here you go - remember to put the first part in the File Open bit as I explained above:




Private Sub Document_Open()

 

Dim bodytext As String

 

    bodytext = Now() & vbLf     'get time

    bodytext = bodytext & Application.UserName & vbLf   'get username of word user

    bodytext = bodytext & "whatever else you want"      'body text stuff

    

   Call SendDocumentInMail("Subject Line", "me@mymail.com", bodytext)

 

End Sub
 

Sub SendDocumentInMail(strSubject As String, strTo As String, strBody As String)
 

Dim bStarted As Boolean

Dim oOutlookApp As Outlook.Application

Dim oItem As Outlook.MailItem
 

On Error Resume Next
 

'Get Outlook if it's running

Set oOutlookApp = GetObject(, "Outlook.Application")

If Err <> 0 Then

    'Outlook wasn't running, start it from code

    Set oOutlookApp = CreateObject("Outlook.Application")

    bStarted = True

End If
 

'Create a new mailitem

Set oItem = oOutlookApp.CreateItem(olMailItem)
 

With oItem

    'Set the recipient for the new email

   .To = strTo

    'Set the recipient for a copy

    '.CC = "recipient2@mail.com"

    'Set the subject

    .Subject = strSubject

    'The content of the document is used as the body for the email

    .Body = strBody

    .Send

End With
 

If bStarted Then

    'If we started Outlook from code, then close it

    oOutlookApp.Quit

End If
 

'Clean up

Set oItem = Nothing

Set oOutlookApp = Nothing
 

End Sub

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I. Introduction In a previous article (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_6537-PaperPort-Upgrade-How-to-download-and-install-updated-versions-of-PaperPort-11-and-12.html) (now deprecated), I discussed how to upgrad…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now