Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    May 2009
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm using Word 2003 to develop a form with an email button. When clicked, it opens Lotus Notes and adds the form as an attachment. Company still has some Word 97 users, if that's important.

    This bit of code works great but what must be added to this code to automatically prefill the To: field and the Subject: field? I've looked through dozens of posts here, in the VBA section, and on other newsgroups but almost all of them have to do with Outlook as the mail application which doesn't help me. I've looked at Word's VBA Help but couldn't find an example that worked.

    ActiveDocument.SendMail

    Thanks,
    Charlie
    charlie6067

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I fear that you'll find few Loungers who know how to automate Lotus Notes...

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Years ago I did something like this and used the following code may still work. I found the original of this source somewhere on the net but don't have the source code anymore. This should be enough to either get you up and running or at least give you some search terms to allow you to find relevant code somewhere else on the net.
    [codebox]Option Explicit
    '========================================
    Public Sub SendEmailInNotes()
    'Tries to send activedocument as email attachment using Lotus Notes
    'User needs to have Notes open before running this code as code doesn't
    ' handle logon and startup switches complexities
    'Requires VBA references set to:
    '' Lotus Notes Automation Classes &/or
    '' Lotus Domino Objects

    'Prepare the variables:
    Dim uidoc As lotus.NOTESUIDOCUMENT
    Dim uiworkspace As Object, session As Object
    Dim db As Object, field As Object
    Dim nview As Object, domDocumentCollection As Object
    Dim doc As Object, doc2 As Object
    Dim sTempString As String, sMailFile As String
    Dim sMailServer As String, sMailType As String

    'Save the document
    ActiveDocument.Save

    'Checks for an active Lotus Notes session:
    If funTaskRunning("Lotus Notes") = False Then
    MsgBox "Lotus Notes is not running at present. Before you proceed make sure Lotus Notes is running!"
    Exit Sub
    End If

    'This is the code that starts a Notes-session (if one is not already active)
    ' and prepares and sends the email:

    'Create a Notes-session:
    Set session = CreateObject("Notes.NotesSession")
    Set uiworkspace = CreateObject("Notes.NotesUIWorkspace")

    'Get environment-specific information:
    sTempString = session.GETENVIRONMENTSTRING("Location", True)
    sTempString = Left(sTempString, InStr(sTempString, ",") - 1)
    Set db = session.GETDATABASE("", "NAMES.NSF")
    Set nview = db.GETVIEW("Locations")
    Set domDocumentCollection = nview.GETALLDOCUMENTSBYKEY(sTempString)
    Set doc = domDocumentCollection.GETFIRSTDOCUMENT
    sMailFile = doc.GETITEMVALUE("MailFile")(0)
    sMailType = doc.GETITEMVALUE("MailType")(0)
    If sMailType = "1" Then
    sMailServer = ""
    Else
    sMailServer = doc.GETITEMVALUE("MailServer")(0)
    End If

    'Create the mail and attach the document:
    Set db = session.GETDATABASE(sMailServer, sMailFile)
    Set doc = db.CREATEDOCUMENT
    doc.Form = "Memo"
    'doc.SendTo = bestemming$
    doc.Subject = ActiveDocument.Name
    doc.CREATERICHTEXTITEM ("Body")
    Set field = doc.GETFIRSTITEM("Body")
    Call field.EMBEDOBJECT(1454, "", ActiveDocument.FullName, "Word attachment")

    ' 'Delete an optional added signature:
    ' Call uiworkspace.OpenDatabase(sMailServer, sMailFile)
    ' Set doc2 = uiworkspace.EDITDOCUMENT(True, doc)
    ' Call doc2.FIELDCLEAR("Body")

    'Bring to front on screen
    doc2.Activate

    'Clean up
    Set db = Nothing
    Set doc = Nothing
    Set session = Nothing
    Set uiworkspace = Nothing
    Set field = Nothing

    ' 'Send the email
    ' Call doc2.SEND(False)
    ' Call doc2.Close
    End Sub

    Public Function funTaskRunning(sTaskName As String) As Boolean
    'Checks for an active task by name:
    Dim oTask As Task
    funTaskRunning = False
    For Each oTask In Tasks
    If InStr(oTask.Name, sTaskName) Then
    funTaskRunning = True
    End If
    Next oTask
    End Function[/codebox]
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Star Lounger
    Join Date
    May 2009
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='Andrew Lockton' post='777543' date='29-May-2009 21:17']Years ago I did something like this and used the following code may still work. I found the original of this source somewhere on the net but don't have the source code anymore. This should be enough to either get you up and running or at least give you some search terms to allow you to find relevant code somewhere else on the net.
    [codebox]Option Explicit
    '========================================
    Public Sub SendEmailInNotes()
    'Tries to send activedocument as email attachment using Lotus Notes
    'User needs to have Notes open before running this code as code doesn't
    ' handle logon and startup switches complexities
    'Requires VBA references set to:
    '' Lotus Notes Automation Classes &/or
    '' Lotus Domino Objects

    'Prepare the variables:
    Dim uidoc As lotus.NOTESUIDOCUMENT
    Dim uiworkspace As Object, session As Object
    Dim db As Object, field As Object
    Dim nview As Object, domDocumentCollection As Object
    Dim doc As Object, doc2 As Object
    Dim sTempString As String, sMailFile As String
    Dim sMailServer As String, sMailType As String

    'Save the document
    ActiveDocument.Save

    'Checks for an active Lotus Notes session:
    If funTaskRunning("Lotus Notes") = False Then
    MsgBox "Lotus Notes is not running at present. Before you proceed make sure Lotus Notes is running!"
    Exit Sub
    End If

    'This is the code that starts a Notes-session (if one is not already active)
    ' and prepares and sends the email:

    'Create a Notes-session:
    Set session = CreateObject("Notes.NotesSession")
    Set uiworkspace = CreateObject("Notes.NotesUIWorkspace")

    'Get environment-specific information:
    sTempString = session.GETENVIRONMENTSTRING("Location", True)
    sTempString = Left(sTempString, InStr(sTempString, ",") - 1)
    Set db = session.GETDATABASE("", "NAMES.NSF")
    Set nview = db.GETVIEW("Locations")
    Set domDocumentCollection = nview.GETALLDOCUMENTSBYKEY(sTempString)
    Set doc = domDocumentCollection.GETFIRSTDOCUMENT
    sMailFile = doc.GETITEMVALUE("MailFile")(0)
    sMailType = doc.GETITEMVALUE("MailType")(0)
    If sMailType = "1" Then
    sMailServer = ""
    Else
    sMailServer = doc.GETITEMVALUE("MailServer")(0)
    End If

    'Create the mail and attach the document:
    Set db = session.GETDATABASE(sMailServer, sMailFile)
    Set doc = db.CREATEDOCUMENT
    doc.Form = "Memo"
    'doc.SendTo = bestemming$
    doc.Subject = ActiveDocument.Name
    doc.CREATERICHTEXTITEM ("Body")
    Set field = doc.GETFIRSTITEM("Body")
    Call field.EMBEDOBJECT(1454, "", ActiveDocument.FullName, "Word attachment")

    ' 'Delete an optional added signature:
    ' Call uiworkspace.OpenDatabase(sMailServer, sMailFile)
    ' Set doc2 = uiworkspace.EDITDOCUMENT(True, doc)
    ' Call doc2.FIELDCLEAR("Body")

    'Bring to front on screen
    doc2.Activate

    'Clean up
    Set db = Nothing
    Set doc = Nothing
    Set session = Nothing
    Set uiworkspace = Nothing
    Set field = Nothing

    ' 'Send the email
    ' Call doc2.SEND(False)
    ' Call doc2.Close
    End Sub

    Public Function funTaskRunning(sTaskName As String) As Boolean
    'Checks for an active task by name:
    Dim oTask As Task
    funTaskRunning = False
    For Each oTask In Tasks
    If InStr(oTask.Name, sTaskName) Then
    funTaskRunning = True
    End If
    Next oTask
    End Function[/codebox][/quote]


    Hi Andrew,
    Many thanks for sending the requested code. I will try it out next week when back at work. Have a great weekend!

    Hi Hans,
    Thanks for the recommendation - I'm glad to find a group that has some Lotus Notes users. So many companies in US use Group Wise or Outlook. It's good to have a group for posting these questions. Have a great weekend.

    Charlie
    charlie6067

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •