+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Changing VBA code from Outlook to Lotus Notes

  1. #1
    Registered User
    Join Date
    01-09-2008
    Posts
    17

    Changing VBA code from Outlook to Lotus Notes

    Hi All,

    I would appreciate some expertise on this issue.

    I have the following code from Ron De Bruin's website (http://www.rondebruin.nl/mail/folder3/message.htm) for emailing a small message from a range.

    Sub TestFile()
        Dim OutApp As Object
        Dim OutMail As Object
        Dim cell As Range
     
        Application.ScreenUpdating = False
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
     
        On Error GoTo cleanup
        For Each cell In Sheets("Sheet1").Columns("B").Cells.SpecialCells(xlCellTypeConstants)
            If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0, 1).Value) = "yes" Then
                Set OutMail = OutApp.CreateItem(0)
     
                On Error Resume Next
                With OutMail
                    .To = cell.Value
                    .Subject = "Reminder"
                    .Body = "Dear " & cell.Offset(0, -1).Value & vbNewLine & vbNewLine & _
                            "Please contact us to discuss bringing your account up to date"
                    'You can add files also like this
                    '.Attachments.Add ("C:\test.txt")
                    .Send  'Or use Display
                End With
                On Error GoTo 0
    
                Set OutMail = Nothing
            End If
        Next cell
    
    cleanup:
        Set OutApp = Nothing
        Application.ScreenUpdating = True
    End Sub
    I'm ok editing the code to fit in with the spreadsheet I wish to apply it to but the problem I have is that our company uses Lotus Notes (v7) and I have no idea how to amend the code to work with Notes.

    Any help anyone can offer would be greatly appreciated.

    Tom

  2. #2
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,714

    Smile

    Good morning tommytee

    You're better off starting from scratch to be honest. This code should get you started to send a straight forward e-mail - just amend it to suit. I don't have access to Notes 7, but have tested it on Notes 6.5. I would be interested in confirmation that it works OK on the latest version.

    Sub EmailUsingNotes()
    Dim oSess As Object, oDB As Object, oDoc As Object
    Dim oItem As Object, direct As Object
    Dim Var As Variant, flag As Boolean
    Set oSess = CreateObject("Notes.NotesSession")
    Set oDB = oSess.GETDATABASE("", "")
    Call oDB.OPENMAIL
    flag = True
    If Not (oDB.IsOpen) Then flag = oDB.Open("", "")
    If Not flag Then
    MsgBox "Can't open mail file: " & oDB.SERVER & " " & oDB.FILEPATH
    GoTo exit_SendAttachment
    End If
    On Error GoTo err_handler
    'Building the message
    Set oDoc = oDB.CREATEDOCUMENT
    Set oItem = oDoc.CREATERICHTEXTITEM("BODY")
    oDoc.Form = "Memo"
    oDoc.Subject = "" 'Put the subject in here
    oDoc.sendto = "" 'Put the e-mail address in here
    oDoc.Body = "" 'Put the body of your e-mail in here
    oDoc.postdate = Date
    oDoc.SaveMessageOnSend = True
    'Setting up attachments
    Call oItem.EmbedObject(1454, "", "C:\MyAttachment.xls") 'Put the full path to any attachments here
    oDoc.visable = True
    oDoc.Send False
    exit_SendAttachment:
    On Error Resume Next
    Set oSess = Nothing
    Set oDB = Nothing
    Set oDoc = Nothing
    Set oItem = Nothing
    Exit Sub
    err_handler:
    If Err.Number = 7225 Then
    MsgBox "File doesn't exist"
    Else
    MsgBox Err.Number & " " & Err.Description
    End If
    On Error GoTo exit_SendAttachment
    End Sub
    HTH

    DominicB

  3. #3
    Registered User
    Join Date
    01-09-2008
    Posts
    17
    Hi Dominic,

    Thanks for your prompt reply. Let me firstly apologise as I am a novice in this area at the moment but I'm not sure this is exactly what I need. (I'm apologising because I could be wrong!)

    The basic situation is thus:

    I will have a list of contacts (A:A) with email addresses (B:B) and the idea was to have check box linked to cells in C:C and then based on the 'True' or 'False' value in cell C, open a separate message for each inidividual.

    This will be partly a manual process, i.e. an administrator will decide who needs to receive an email based on other information within the spreadsheet and check the boxes accordingly, then run the code to execute this.

    I hope this makes sense and thanks again

    Tom

  4. #4
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,714

    Smile

    Hi tommytee

    Firstly, will you check that the code above works - do this by finding the cells where comments are added and add a body, a header, and an addressee and just run the code to make sure that this code works OK on Notes 7.

    Then let me know where the body of the e-mail will be, and where the header will be, perhaps providing a cut down version of what you have at the moment. Also, I'm guessing that the "contact" in column A is to be the salutation (eg Dear tommytee etc)?

    HTH

    DominicB

  5. #5
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    You will probably find it easier to just put a x in column C & use the code to check for that value instead of checkboxes. Alternatively, you can format C to Marlett Font & use "a" to get a check mark.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  6. #6
    Registered User
    Join Date
    01-09-2008
    Posts
    17
    Hi Dominic,

    Exciting stuff! The code works fine in Notes 7. Really good stuff thanks

    The only thing I would say is that there will definitely be no attachment and I would probably like to open the emails to be checked rather than immediately sent (altho that is very cool).

    The body text would be something along the lines of;

    Dear 'Salutation'

    Your Contract is due to expire on 'Date'

    Please let me know if you would like to renew to 'Date2' as soon as possible..

    With my limited knowledge, I imagine the text that will remain constant can be contained within the code and the specifics in bold kept on the spreadsheet and pulled through from there?

    I've attached up a basic template of what kind of data fields will be there. You will see that there is a manager email too. I will also need the option to email these guys as well with slightly different text in the email body.

    I hope this makes sense

    Cheers

    Tom
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-09-2008
    Posts
    17
    Thanks Roy,

    My intention was to link the check box to each cell to return a TRUE/FALSE and reference that in the code, but I'm not sure if thats the best way.

    Tom

  8. #8
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    Quote Originally Posted by tommytee View Post
    Thanks Roy,

    My intention was to link the check box to each cell to return a TRUE/FALSE and reference that in the code, but I'm not sure if thats the best way.

    Tom
    I think you will find it simpler to do what I suggested. Check the example, double click any cell in column C to add the check (tick), remove it if not required. Code is in the Worksheet module.
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  9. #9
    Registered User
    Join Date
    01-09-2008
    Posts
    17
    Hi Roy,

    Thanks for that code - top notch!

    I'll definitely use that

    Tom

  10. #10
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,714

    Smile

    Hi tommytee

    Roy's suggestion would be easier than to create 500 tick boxes : that said the example I have used utilises a tick box, as I have only one row to cater for. If you want to go for Roy's example, no great changes will be required.

    To kick the thing off in your example you will need to run the macro "BuildMessage" which will loop through all rows and send an e-mail based on the information in the sheet where column N says True.

    I am looking into saving the resultiung e-mail into drafts, but this is not quite as simple as it would be in Outlook. Unsurprisingly, Notes doesn't integrate into Office quite as well as Microsoft products do - in fact it is the command
    oDoc.postdate = Now()
    which places the mail into the sent folder, so it's not quite as straightforward as one might think.

    HTH

    DominicB
    Attached Files Attached Files

  11. #11
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    Hi Dominic, does Notes not have a .Show command or similar?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  12. #12
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,714

    Smile

    Quote Originally Posted by royUK View Post
    Hi Dominic, does Notes not have a .Show command or similar?
    Thanks for the thought Roy, but unfortunately, but the .Show command (and is there also a .Display command?) are unsupported, however I've found a .Save instruction that seems to work with a slight syntax tweak, so TommyTee in the macro replace this line :
    oDoc.Send False
    with this :
    Call oDoc.Save(True, False)
    to get the unsent mail to go to your Drafts folder for review.

    HTH

    DominicB

  13. #13
    Registered User
    Join Date
    01-09-2008
    Posts
    17
    That's amazing.

    I've tweaked a bit of the text but its really starting to look like what I wanted so many thanks for your helps guys.

    I was just trying to use Roy's code for double clicking but can't seem to get it to work in the test sheet. I wanted to change it to column A aswell but couldn't see how to do it.

    Cheers

    Tom

  14. #14
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,714

    Smile

    Hi tommytee
    Quote Originally Posted by tommytee View Post
    I was just trying to use Roy's code for double clicking but can't seem to get it to work in the test sheet. I wanted to change it to column A aswell but couldn't see how to do it.
    Not quite sure what you mean, but if you're really struggling feel free to upload a small sample of where you're up to and someone will try and help you out.

    DominicB

  15. #15
    Registered User
    Join Date
    01-09-2008
    Posts
    17
    Ok,

    This is the original code from Roy

    Option Explicit
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'limit action to C
    If Target.Column <> 3 Then Exit Sub
    If IsEmpty(Target) Then
    With Target
    .Value = "a"
    .Font.Name = "Marlett"
    End With
    Else: Target.ClearContents
    End If
    End Sub
    All I did was paste it into the test spreadsheet module below everything else but I couldn't work out how it actually works! I couldn't see how it was limited to column C (as the 'limit action to C' was just a label I think)

    Also do I need to use a separate module?

    Thanks

    Tom

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Zip File And Mail With Lotus Notes
    By mridzuan in forum Excel Programming
    Replies: 0
    Last Post: 01-30-2007, 01:22 AM
  2. Sending Excel through email using Lotus Notes
    By mridzuan in forum Excel Programming
    Replies: 7
    Last Post: 01-25-2007, 09:29 PM
  3. Problems understanding automated emailing code.
    By DDONNI in forum Excel Programming
    Replies: 15
    Last Post: 01-19-2007, 11:26 AM
  4. emailing from excel via lotus notes
    By chris_mayer in forum Excel Programming
    Replies: 0
    Last Post: 09-27-2006, 07:56 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0