Create Mail in edit mode using VBA

Not very skilled at VBA, but I found the following (and variants) that gets close to what I want, except that it automatically sends the mail.

Instead, I’d like the maildoc be created, subject added, attachment added, and default To: be added, then allow the user to continue editing the doc (add CC:, modify the body, etc.) and then they do a manual send. To be used by a very small workgroup, with the full client installed. Any suggestions?

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)

'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")

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

Subject: Create Mail in edit mode using VBA

Ted,

The reason you aren’t seeing the e-mail is because you do not have a NotesUIWorkspace or NotesUIDocument object called. However, I do not believe these objects are available via COM. You would have to run this script in a Notes client to use those objects.

Sorry.

brandt

Subject: RE: Create Mail in edit mode using VBA

Actually, I believe if Ted makes a reference to the “Lotus Notes Automation Objects” in his VB project, he will be able to use the UI classes. What he probably has a reference to is the “Lotus Domino Objects”, which as you correctly point out, Brandt, do not have UI classes.

Ted, if you already have a reference to the “Lotus Notes Automation Objects”, you will need to work with the NotesUIDocument object. See the designer help here and search for NotesUIDocument for examples of how to work with it.

http://www-12.lotus.com/ldd/doc/domino_notes/7.0/help7_designer.nsf/Main?OpenFrameSet

Subject: RE: Create Mail in edit mode using VBA

Cesar -Yes, I’ve got the LN Automation Objects, the struggle was learning what was what (also have the Domino). Thanks so much for pointing me in the right direction, the Designer help looks to be exactly what I was searching for.

Subject: Create Mail in edit mode using VBA

Hi Ted.

I may be wrong, but did you try to just remove the “Send” instruction from your code?

'Send the document

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

MailDoc.Send 0, Recipient <------- Here is where the document is sent.

I believe that if you do everything, but not send the memo, it will remain opened, “waiting” for an action…

Try REMarking that line, or the whole section and execute the script.

Hope it helps.

Rubens

Subject: RE: Create Mail in edit mode using VBA

Thanks Rubens -Nothing so simple, unfortunately. In my client, there is nothing - no open doc, no trace of it. I’m hoping there is something like “MailDoc.Edit” or “MailDoc.Show” or some such that can be invoked…

Ted