Solved

Read receipt when Word document is opened

Posted on 2009-05-07
4
500 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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
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…

920 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

17 Experts available now in Live!

Get 1:1 Help Now