Question

Sending multiple emails through Lotus Notes from Excel VBA

Asked by: lilputian

I am using Excel VBA code to send emails via Lotus Notes, using a FOR Loop.  I am running into 2 problems:
1)  After sending the Document, Lotus Notes keeps the window open.  I'm not sure why the Save wouldn't close the window.
2)  I have pasted an excel range into the body of the memo.  When it sends the email, it appears to transform the body into a jpg file attachment.  I would like to leave the picture displayed in the body of the memo.

Here's my code:
    Set oWorkspace = CreateObject("Notes.NotesUIWorkspace")
    Set oSession = CreateObject("Notes.NotesSession")
    Set oDatabase = oSession.GETDATABASE(notesServer, notesDBName)
    If oDatabase.IsOpen Then
    Else
        oDatabase.OpenMail
    End If

    For i = 3 To 100
        sSendTo = Trim(uIfNull(Sheets("EmpHDR").Cells(i, 12).value))
' Setup Document
        Set oDoc = oDatabase.CREATEDOCUMENT()
        With oDoc
            .Form = "Memo"
            .sendto = sSendTo
            .Subject = "TEST"
        End With
        sRange = "B3:M50"
        Sheets("Test").Select
        Sheets("Test").Range(sRange).Select
        Selection.Copy
 
        Set uiDoc = oWorkspace.EDITDOCUMENT(True, oDoc)
        Call uiDoc.GOTOFIELD("Body")
        Call uiDoc.Paste
        Call uiDoc.Save

        Set oDoc = uiDoc.DOCUMENT
       Call oDoc.Save(True, True)
        With oDoc
              .SAVEMESSAGEONSEND = False
              .send 0, sSendTo
        End With
'**************************************************************************************
' clear clipboard
    Sheets("Test").Select
    Sheets("Test").Range("A1").Select
    Selection.Copy
'**************************************************************************************
'   Cleanup
    Set oDoc = Nothing
    Set uiDoc = Nothing
   
    Next i
    Set oWorkspace = Nothing
    Set oSession = Nothing
    Set oDatabase = Nothing

     

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-05-06 at 03:00:36ID22555251
Tags

lotus

,

notes

,

vba

,

excel

,

send

Topics

VB Objects

,

Lotus Notes

,

Microsoft Excel Spreadsheet Software

Participating Experts
3
Points
250
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. excell an lotus
    what is the diference between lotus an excell?
  2. how to open a lotus notes document from Excel using VBA …
    Hi Experts, If some one can help me in setting a link in excel sheet to the lotus notes document.I have 100 lotus notes document in the excel sheet. i have also got the notes url feild. but i want to write a vba code which automaticaly sets the link for the n...
  3. Access VBA and Lotus Notes
    I have a button on an Access form, when the user clicks on it an email is sent via Lotus Notes. Is there anyway to only create the email but not actually send it?
  4. Lotus Notes Database query with Excel VBA
    Hi experts, I'm trying to do what I'm sure has been done over and over. I am not new to Notes databases or to Excel VBA, but I am new to using them together. I'm trying to pull records from a view and I'm successful as long as I only use one key. When I try to switch to m...
  5. VBA test for Lotus Notes Replication
    Hi all, I have a VBA application that interacts with a local replica of a Lotus Notes database. I would like to test (via VBA) to see if the database is replicating. Thoughts? TIA!
  6. VBA code for importing table from Lotus Approach
    I need the VBA code for importing a table of Lotus Approach format with extension "dbf" into Access 2003.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: lilputianPosted on 2007-05-06 at 07:44:48ID: 19038994

I had done some extensive searching myself.  The links you mentioned, unfortunately do not addess my questions.

 

by: marilyngPosted on 2007-05-06 at 11:21:52ID: 19039612

Ok, it seems that you are calling a UIDOC to open and paste clipboard contents into a Notes Rich Text field, rather than building the mail document from the back end, and attaching or embedding object.

That will cause the paste to be a picture rather than an Excel Object that can be opened and edited.

Also, you have to close the uidoc :)

when you set:

 Set oDoc = uiDoc.DOCUMENT

       Call oDoc.Save(True, True)

you can also set: uidoc.close(true), to close the open document.  The "true" will force the close.

However, you might get a "Do you want to Save" message in the UI, since you also have to manipulate a "SaveOptions" field and set it to "0" before you call the close, and then delete the field after the document is closed, else, subsequently opening and editing the document will prevent users from saving it.

 

by: lilputianPosted on 2007-05-06 at 12:16:02ID: 19039735

I am attempting to send out Pay statements to the employee email addresses.  I setup a template in Excel to accomplish this task.  The request has been to display the info as a rich text object in the Body rather than as an attachment.  I'm not sure that my code is the best approach.  I would appreciate some feedback.  It appears I only have Excel to work with and Lotus Notes, but if there is a better, cheap solution, I'm game.  Maybe I should just use the same memo, and do a clear before each paste. What do you think?

Can't seem to get the Save prompt to disappear.   I do not want a copy saved in my inbox.

Call uiDoc.Save
Set oDoc = uiDoc.DOCUMENT
oDoc.saveOptions = "0"
oDoc.send
Call uiDoc.Close(True)
??? Delete field

 

by: patrickabPosted on 2007-05-06 at 12:38:15ID: 19039789

If you are starting with Excel there should be no need to go through Lotus Notes. Instead why not get Excel to email each employee directly. You should be able to find what you need to do that in this link:

http://www.rondebruin.nl/sendmail.htm

 

by: lilputianPosted on 2007-05-06 at 14:03:13ID: 19039979

In the end, all the examples use some sort of mail client, usually refers to Outlook.  We only have Lotus Notes installed.  

 

by: patrickabPosted on 2007-05-06 at 14:59:51ID: 19040093

OK, understood. Back to the drawing board!

 

by: Bill-HansonPosted on 2007-05-07 at 07:29:06ID: 19042877

If you need to see the cells in the body, then pasting the image is the best you can hope for.  Every other method will display an icon.

You could use EmbedObject(1453, "", FileToSend), which will embed the actual spreadsheet as an object, but it still displays as an icon until the user double-clicks it.  At that point, the Excel object will activate and display directly in the body.

You could use EmbedObject(1454, "", FileToSend), but that results in a file attachment, not an embedded object.

It would be nice if the powers-that-be at Lotus would expose the DisplayAs property.  The property exists, but is not exposed via the COM object.  The choices for the setting are Bitpam, Picture, Text, Rich Text, or Icon.

If the property existed (alas), we could just use:
set obj = body.EmbedObject(1453, "", FileToSend)
obj.DisplayAs = RichText

To see this property in action, use EmbedObject(1453, "", FileToSend).  Then open the email in edit mode, select the object and display the object properties window.  You will see the setting I am referring to.  Change it to "Rich Text" and you'll see what you want to accomplish.

Is it time to put more pressure on Lotus to add this feature?

 

by: lilputianPosted on 2007-05-07 at 10:14:42ID: 19044182

Thanks, that was helpful.  I suppose the Paste as Special (rich text) is also not available.  I don't know a lot about Lotus Notes, but is it possible to do what I am attempting, in Lotus Notes?  
1.   Create recordset using ODBC  
2.   Populate a Lotus Memo / Form (Template)
3.   Send email to recipient
or ...
Is it possible for Lotus Notes to scan for a particular Subject line and do it's own processing, ie. copy / paste attachment into body and then send to recipient

Thanks
 

 

by: Bill-HansonPosted on 2007-05-07 at 10:50:44ID: 19044484

You can do just about everything you mentioned, except embedding an object and have it appear the way you want.  Notes is very flexible.  This is just one of the frustrating situations where it will not do exactly what you want, but there is always a work-around...

If you're using Notes R6 or later, you could use VBA to re-create the spreadsheet as an HTML table using MIME or RichText (just like creating a report from Excel using VBA).  I prefer this way over using the embedded object (even if we could control the display), because you have complete control over the appearance of the email.  Of course, if you need the table to function as a spreadsheet (ie: perform computations), this workaround is not for you.  But if you just need a static report, and the spreadsheet is in a somewhat standard format, this could be what you're looking for.

 

by: marilyngPosted on 2007-05-07 at 11:35:55ID: 19044832

Bill, essentially true.   The problem is exporting a range in excel as a file that can be used to embed.   There is no direct way to do it, and the copy cells>>paste, is a clever solution if you can get the UIDOC calls to work in Excel VB.   They don't seem to be available :)

To use the embed object, you have to be a bit more clever with Excel, and grab the picture and paste that picture into a CHART, which you can then save to a file in Excel VB.  (I can be wrong, this is TOL).  Once you have a saved file, you can use that file to embed object as a picture using the 1453 call.

Popluating a richtext item using the table and formatting is another way to go, as Bill explains.

I'm thinking another way might be to construct a HTML file via a TEXT file in Excel VB, and then embed that, assuming the richtext paragraph style is available via COM.

Would have to test to be sure.  :)  Whatcha think?

 

by: Bill-HansonPosted on 2007-05-07 at 12:18:45ID: 19045196

I didn't know that about the chart workarond.  Thanks marilyng!  I still prefer to stay in the backend, though.

 

by: lilputianPosted on 2007-05-07 at 13:24:45ID: 19045716

If I go with the copy / paste method, how do I handle the loop?  Can I send the message, clear the body, setup the next message, send that message etc.  without having the SEND .. SAVE  message appearing.

 

by: Bill-HansonPosted on 2007-05-07 at 13:32:36ID: 19045780

Just one of the reasons I try to avoid the front-end workaround.

You can prevent the save/send message, however, by saving the uidoc, setting doc.SaveOptions to "0", then calling uidoc.Close().  Just don't forget to remove the SaveOptions field before calling the backend Send function.

 

by: marilyngPosted on 2007-05-07 at 16:12:02ID: 19046630

Ok, I'm a few posts behind now, in order for it to stay totally in the back end you either have to create the table in the rich text field, or paste the selection into a Chart and export the chart as an image.  Then you can   embed the exported file into the Notes Rich Text field without having to call UIDOC.

Either way, your current solution using the UIDOC with a paste function, needs a beefy computer :)

May we ask what you have in the excel file that can't be totally transferred into a Notes Database?  Sounds like you're using the excel file as a database, anyway. :)

 

by: lilputianPosted on 2007-05-08 at 12:08:00ID: 19052290

I am creating Pay Statements that need to be mailed to each employee.  The Excel file reads the Payroll Database (an outside system), and creates a sheet formatted for email purposes.  The employees can of course have different email clients.  I had also looked at creating a PDF file and sending that.  I only have Lotus Notes available for emailing.  I could possible get access to do some development in the Lotus side of things.  Any thoughts?  Thanks.    

 

by: Bill-HansonPosted on 2007-05-08 at 13:34:25ID: 19052850

If it was me, I would try marilyng's chart workaround.  If I was not happy with that, I would parse the Excel sheet and create my own table using MIME.

 

by: lilputianPosted on 2007-05-14 at 21:11:40ID: 19090434

I did some more testing and found that the Copy and Paste method created some fairly huge files.  I decided to create PDF files and send them as an attachment.  It's slower but appears to work.  I appreciate both your comments.  Most likely my initial post was not a good universal approach when dealing with different email clients.  However, I would like to award the points to both of you.  Question is, which posts do I mark as the solution?  Thanks.  

 

by: marilyngPosted on 2007-05-15 at 10:09:27ID: 19094438

If you're sending as an attachment, then Bill's 19042877 seems like the correct answer.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...