Consulting

Results 1 to 18 of 18

Thread: Move Lotus Notes mail to a folder in Lotus Notes through VBA

  1. #1

    Move Lotus Notes mail to a folder in Lotus Notes through VBA

    Hello Everyone

    I am a new member to this forum.

    I searched for my query in this forum but not able to find the answer. Please forgive me if these kind of questions were already answered in past.

    I got a task where I have to to create VBA which will detach attachments from LN inbox mails, delete the attachment, move those mails to a Lotus Notes folder and finally send automatic reply mail to sender.

    I am able to detach attachments from mail but not able to move mail documents from Inbox to "Cleared" folder in LN.

    This is what I have used :
    ..................
    If (attch.Type = EMBED_ATTACHMENT) Then
    attch.ExtractFile sPathToSave & attch.Name 'save attachment to directory
    attch.remove 'delete attachment from mail
    End If
    doc.PutInFolder "Cleared", True 'copy mail to Cleared Folder in LN
    doc.Removefromfolder "($Inbox)", True 'delete mail from inbox
    ........................

    This code makes copy of first mail in 'Processed' folder of LN but never delete mail from Inbox. In fact, it create two copies which are seemed to be linked. That means if I delete mails from inbox (after code run) mails also get deleted from 'Processed' folder. Moreover, due to this issue the loop is running on the first mail only.

    Can someone please help me and guide me on this.
    Thanks.

  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Welcome to VBAX. I suppose (for what you are looking for) you will not require Excel VBA but creating agent in LN. You will find some useful links by googling and LN / IBM normally post the name of Application Support Engineer to whom you can contact.
    http://www.nsftools.com/tips/NotesTips.htm
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  3. #3
    Thanks for reply Shrivallabha.

    yes, this is possible through Lotusscript but we are not allowed to access Domino Designer, thats the reason I am trying to do this from Excel VBA.
    Any advice on this please.

  4. #4
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    I have faced some difficulties in achieving desired results. It was one-off assignment so I may not prove to be the right person to get help from. However, there are a few things that may provide you some good leads:
    http://www.vbaexpress.com/forum/show...ht=Lotus+Notes

    Also, in VBE select the Lotus Notes references option using Tools>>References so that you can see the available objects using Object Browser.

    I might be of little help but you may post back your requirements. Lets see if we can take it from there. All the best!
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Shrivallabha has provided some good direction. I would think that you would want to try some things used in: http://www.rondebruin.nl/notes1.htm

    I would recommend that you use early binding methods as previously recommended. This makes it easier to program but makes no significant difference otherwise. The method at Ron's site uses late binding. I commented on how to do the early binding in: http://www.vbaexpress.com/forum/showthread.php?t=16109

    To get more help here, I suggest that you post the full code so that we can test.

  6. #6
    Try:

    doc.Save True, False

    before the PutInFolder, to commit changes to the document.

  7. #7
    Thanks a ton to all of you.

    Shrivallabha: LN reference is already made in VBA. If possible, please take a look at complete code below.

    Crocus Crow: I tried your suggested code this but still facing the same problem.

    Kenneth Hobs: I checked those links, not able to find code where we can move or delete inbox mails. May be I am doing something wrong here....I don't have much experience in VBA and this is the first time I am trying to connect LN with VBA.

    Please see the complete code below and please advice.

    *******************************************
    Global Const sPathToSave As String = "C:\MailDocs\" ''''''''''path to save mail files
    Global Const RICHTEXT As Long = 1
    Global Const EMBED_ATTACHMENT As Long = 1454 '''''''1454 indicate a file attachment
    ''''''server and mail db path
    Global Const sServerName = "servername"
    Global Const sUserDB = "mailnsf"
    Public NSession As Object 'The notes session
    Public Db As Object 'The notes mail database
    Public MailDoc As Object
    Public Body As Object
    Global sSendTo As String
    Global sSubject As String
    Global SAttchName As String
    Global Const sBodyText As String = "Thank you for your mail."

    Public Sub mail()
    Dim View As Object
    Dim Doc As Object
    Dim NxtDoc As Object
    Dim itm As Variant
    Dim attch As Variant

    ''''''''Create Notes Session
    Set NSession = CreateObject("Notes.Notessession")
    ''''''''Initiate Notes database and get Connection to Mail File
    Set Db = NSession.GetDatabase(sServerName, sUserDB)
    '''''''''Open mailbox if not already open
    ''''If db.IsOpen = False Then Call Db.Openmail
    '''''''''Folers are viwes in LN, get Inbox view
    Set View = Db.GetView("($Inbox)")
    '''''Get to first mail in inbox view
    Set Doc = View.GetFirstDocument

    ''''Iterate through all the emails in the inbox
    While Not Doc Is Nothing
    ''''''A pointer to the next document in the view is established
    Set NxtDoc = View.GetNextDocument(Doc)
    ''''''''Check if the current document has an attachment or not.
    If Doc.HasEmbedded Then
    Set itm = Doc.GetFirstItem("Body")
    If itm.Type = RICHTEXT Then
    ''''''get all attachments
    For Each attch In itm.EmbeddedObjects
    If (attch.Type = EMBED_ATTACHMENT) Then
    '''''get recipients mail id
    sSendTo = Doc.GetItemValue("From")(0)
    '''''get attachment name
    SAttchName = attch.Name
    '''''get subject line
    sSubject = Doc.GetItemValue("Subject")(0)
    '''''Save the attached file into the folder.
    attch.ExtractFile sPathToSave & attch.Name
    '''''Remove attachment from the mail
    attch.Remove
    End If
    Next
    Doc.Save True, False
    Doc.PutInFolder "Cleared", True
    ''''''Delete mail document from Inbox
    'Doc.Remove (True) '''-->not using since delete from both Inbox & Cleared folder
    Doc.Removefromfolder "($Inbox)", True
    '''''====>>>> this is where the real problem exists it never delete mail from inbox, infact make copy in Cleared Folder and create kind of link to Inbox mail and Cleared Folder mail that means if delete mail from any of these folder it get created from both..
    End If
    End If

    ''''''''calling reply mail
    Set MailDoc = Db.CreateDocument
    MailDoc.Form = "Memo"
    MailDoc.sendto = sSendTo
    MailDoc.Subject = "Re: " & sSubject & " - " & SAttchName
    MailDoc.Body = sBodyText
    MailDoc.SaveMessageOnSend = True
    ' '''''''''''Saving message
    MailDoc.PostedDate = Now()
    'MailDoc.Send 0, sSendTo
    MailDoc.Send False

    ''''Refresh Inbox ===>>> i guess none of these working...i am trying to refresh mailbox by this.
    Call View.Refresh
    Call NSession.UpdateProcessedDoc(Doc)

    ''''Set current document pointer
    Set Doc = NxtDoc

    Wend

    '''''release all memory
    Set MailDoc = Nothing
    Set Body = Nothing
    Set NxtDoc = Nothing
    Set Doc = Nothing
    Set View = Nothing
    Set Db = Nothing
    Set NSession = Nothing
    End Sub
    ****************************************************

  8. #8
    Your code did the same for me: it saved and removed any attachments, copied the mail document to the specified folder, but also kept it in the Inbox.

    Try using the Lotus Domino Objects (COM classes) instead of OLE objects. To do this, change:

    Set NSession = CreateObject("Notes.Notessession")
    to:
    Set NSession = CreateObject("Lotus.NotesSession")
    You might need other changes to go with this change.

    Also, please post your code within [ code ] tags to preserve the indentation (I assume you have indented it properly in the VB editor) and make it easier to see the overall structure.

    Correction:
    Please enclose your code within [vba] tags as this correctly indents the code. Other forums use [Code] but here at VBAEXPRESS we prefer the [vba] tags instead. You can simply select your code and click on the green VBA button to wrap code or simply click the green VBA button and insert your code within the tags
    Last edited by Aussiebear; 05-27-2011 at 06:46 PM. Reason: Correction of advice offered

  9. #9
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Quote Originally Posted by Crocus Crow
    Your code did the same for me: it saved and removed any attachments, copied the mail document to the specified folder, but also kept it in the Inbox.

    Try using the Lotus Domino Objects (COM classes) instead of OLE objects. To do this, change:

    Set NSession = CreateObject("Notes.Notessession")
    to:
    Set NSession = CreateObject("Lotus.NotesSession")
    You might need other changes to go with this change.

    Also, please post your code within [ code ] tags to preserve the indentation (I assume you have indented it properly in the VB editor) and make it easier to see the overall structure.
    Have you tried your hand with COM objects as you have specified? In the object explorer I had found that Notesession is also a member of Domino but CreateObject method failed to create Domino.Notessession. I must admit that I didn't try Lotus.Notessession.

    @whysoserious: I can give you a feedback by Monday (soonest if I get time that is) when I get a chance to look at LN which is available in office.
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  10. #10
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I won't be in the office until Friday next week. I had similar problems. This does copy the attachments though. If you comment and uncomment the objects for early and late binding, you can use intellisense to explore some methods and properties.

    [VBA]Sub Test_Save_RemoveAttachments()
    Save_Remove_Attachments "mail\khobson.nsf", "C:\MyFiles\Lotus\Notes\Attachments\", "Processed"
    End Sub

    'Similar to: 'http://www.rondebruin.nl/notes1.htm
    Sub Save_Remove_Attachments(theNSF As String, stPath As String, lnPutInFolder As String)
    'Late Bind
    Dim noSession As Object
    Dim noDatabase As Object
    Dim noDocument As Object
    Dim noNextDocument As Object
    Dim noView As Object

    'Early Bind - Tools > Reference > Lotus Notes Automation Classes, notes32.tlb
    ' Dim noSession As lotus.NOTESSESSION
    ' Set noSession = CreateObject("Notes.NotesSession")
    ' Dim noDatabase As lotus.NOTESDATABASE
    ' Set noDatabase = noSession.GETDATABASE("", "mail\username.nsf")
    ' Dim noDocument As lotus.NOTESDOCUMENT
    ' Dim noNextDocument As lotus.NOTESDOCUMENT
    ' Set noNextDocument = noDatabase.CREATEDOCUMENT
    ' Dim noView As lotus.NOTESVIEW

    Dim EMBED_ATTACHMENT As Long
    Dim RICHTEXT As Long

    'Embedded objects are of the datatype Variant.
    Dim vaItem As Variant
    Dim vaAttachment As Variant

    EMBED_ATTACHMENT = 1454
    RICHTEXT = 1

    'Exit if storage path for attachments, stPath, does not exist.
    If Right(stPath, 1) <> "\" Then stPath = stPath & "\"
    If Dir(stPath, vbDirectory) = "" Then
    MsgBox stPath & vbLf & "Macro is ending!", vbCritical, "Storage Path Does Not Exist!"
    Exit Sub
    End If

    'Instantiate the Notes session.
    Set noSession = CreateObject("Notes.NotesSession")

    'Instantiate the actual Notes database.
    '(Here is the personal e-mail database used and since it's a
    'local database no reference is made to any server.)
    Set noDatabase = noSession.GETDATABASE("", theNSF)
    If noDatabase.IsOpen = False Then
    noDatabase.OPENMAIL
    End If

    'Folders are views in Lotus Notes and in this example the Inbox is used.
    Set noView = noDatabase.GetView("($Inbox)")

    On Error GoTo err_h
    'Get the first document in the defined view.
    Set noDocument = noView.GetFirstDocument

    'Iterate through all the e-mails in the view Inbox.
    Do Until noDocument Is Nothing

    'Although the following approach is not necessary for this
    'kind of operations it may be a good approach to use in general.
    Set noNextDocument = noView.GetNextDocument(noDocument)

    'Check if the document has an attachment or not.
    If noDocument.HasEmbedded Then
    Set vaItem = noDocument.GetFirstItem("Body")
    If vaItem.Type = RICHTEXT Then
    For Each vaAttachment In vaItem.EmbeddedObjects
    If vaAttachment.Type = EMBED_ATTACHMENT Then
    'Save the attached file into the new folder and remove it from the e-mail.
    With vaAttachment
    .ExtractFile stPath & vaAttachment.Name
    .Remove
    End With
    'Save the e-mail in order to reflect the deleting of the attached file.
    '(A more sophisticated approach may be considered if several e-mails have
    'several attachments in order to avoid a repeately saving of one e-mail.)
    noDocument.Save True, False, True
    noDocument.PUTINFOLDER lnPutInFolder, True
    noDocument.REMOVEFROMFOLDER "($Inbox)", True
    End If
    Next vaAttachment
    End If
    End If
    Set noDocument = noNextDocument
    Loop

    'Release objects from memory.
    Set noNextDocument = Nothing
    Set noDocument = Nothing
    Set noView = Nothing
    Set noDatabase = Nothing
    Set noSession = Nothing

    MsgBox "All the attachments in the Inbox have successfully been saved and removed." _
    , vbInformation

    'Clean Up
    err_h:
    Set noSession = Nothing
    Set noDatabase = Nothing
    Set noDocument = Nothing
    Set noNextDocument = Nothing
    Set noView = Nothing
    End Sub

    [/VBA]

  11. #11
    Quote Originally Posted by shrivallabha
    Have you tried your hand with COM objects as you have specified? In the object explorer I had found that Notesession is also a member of Domino but CreateObject method failed to create Domino.Notessession. I must admit that I didn't try Lotus.Notessession.

    @whysoserious: I can give you a feedback by Monday (soonest if I get time that is) when I get a chance to look at LN which is available in office.
    ok, Thanks. In the meantime, I will try code provided by KennethHobs.

  12. #12
    Quote Originally Posted by Crocus Crow
    Your code did the same for me: it saved and removed any attachments, copied the mail document to the specified folder, but also kept it in the Inbox.

    Try using the Lotus Domino Objects (COM classes) instead of OLE objects. To do this, change:

    Set NSession = CreateObject(&quot;Notes.Notessession&quot;)
    to:
    Set NSession = CreateObject(&quot;Lotus.NotesSession&quot;)
    You might need other changes to go with this change.

    Also, please post your code within [ code ] tags to preserve the indentation (I assume you have indented it properly in the VB editor) and make it easier to see the overall structure.

    Correction: Please enclose your code within [vba] tags as this correctly indents the code. Other forums use [code] but here at VBAEXPRESS we prefer the [vba] tags instead. You can simply select your code and click on the green VBA button to wrap code or simply click the green VBA button and insert your code within the tags
    Tried COM Classes, its still not working. Yes, I have indented vba code properly in VBA editor, it was just copy-paste here.....i was too blind that didnt notice that there is a VBA Tags option in this forum. Thanks for showing me the right direction.

  13. #13
    Quote Originally Posted by Kenneth Hobs
    I won't be in the office until Friday next week. I had similar problems. This does copy the attachments though. If you comment and uncomment the objects for early and late binding, you can use intellisense to explore some methods and properties.

    [vba]Sub Test_Save_RemoveAttachments()
    Save_Remove_Attachments "mail\khobson.nsf", "C:\MyFiles\Lotus\Notes\Attachments\", "Processed"
    End Sub

    'Similar to: 'http://www.rondebruin.nl/notes1.htm
    Sub Save_Remove_Attachments(theNSF As String, stPath As String, lnPutInFolder As String)
    'Late Bind
    Dim noSession As Object
    Dim noDatabase As Object
    Dim noDocument As Object
    Dim noNextDocument As Object
    Dim noView As Object

    'Early Bind - Tools > Reference > Lotus Notes Automation Classes, notes32.tlb
    ' Dim noSession As lotus.NOTESSESSION
    ' Set noSession = CreateObject("Notes.NotesSession")
    ' Dim noDatabase As lotus.NOTESDATABASE
    ' Set noDatabase = noSession.GETDATABASE("", "mail\username.nsf")
    ' Dim noDocument As lotus.NOTESDOCUMENT
    ' Dim noNextDocument As lotus.NOTESDOCUMENT
    ' Set noNextDocument = noDatabase.CREATEDOCUMENT
    ' Dim noView As lotus.NOTESVIEW

    Dim EMBED_ATTACHMENT As Long
    Dim RICHTEXT As Long

    'Embedded objects are of the datatype Variant.
    Dim vaItem As Variant
    Dim vaAttachment As Variant

    EMBED_ATTACHMENT = 1454
    RICHTEXT = 1

    'Exit if storage path for attachments, stPath, does not exist.
    If Right(stPath, 1) <> "\" Then stPath = stPath & "\"
    If Dir(stPath, vbDirectory) = "" Then
    MsgBox stPath & vbLf & "Macro is ending!", vbCritical, "Storage Path Does Not Exist!"
    Exit Sub
    End If

    'Instantiate the Notes session.
    Set noSession = CreateObject("Notes.NotesSession")

    'Instantiate the actual Notes database.
    '(Here is the personal e-mail database used and since it's a
    'local database no reference is made to any server.)
    Set noDatabase = noSession.GETDATABASE("", theNSF)
    If noDatabase.IsOpen = False Then
    noDatabase.OPENMAIL
    End If

    'Folders are views in Lotus Notes and in this example the Inbox is used.
    Set noView = noDatabase.GetView("($Inbox)")

    On Error GoTo err_h
    'Get the first document in the defined view.
    Set noDocument = noView.GetFirstDocument

    'Iterate through all the e-mails in the view Inbox.
    Do Until noDocument Is Nothing

    'Although the following approach is not necessary for this
    'kind of operations it may be a good approach to use in general.
    Set noNextDocument = noView.GetNextDocument(noDocument)

    'Check if the document has an attachment or not.
    If noDocument.HasEmbedded Then
    Set vaItem = noDocument.GetFirstItem("Body")
    If vaItem.Type = RICHTEXT Then
    For Each vaAttachment In vaItem.EmbeddedObjects
    If vaAttachment.Type = EMBED_ATTACHMENT Then
    'Save the attached file into the new folder and remove it from the e-mail.
    With vaAttachment
    .ExtractFile stPath & vaAttachment.Name
    .Remove
    End With
    'Save the e-mail in order to reflect the deleting of the attached file.
    '(A more sophisticated approach may be considered if several e-mails have
    'several attachments in order to avoid a repeately saving of one e-mail.)
    noDocument.Save True, False, True
    noDocument.PUTINFOLDER lnPutInFolder, True
    noDocument.REMOVEFROMFOLDER "($Inbox)", True
    End If
    Next vaAttachment
    End If
    End If
    Set noDocument = noNextDocument
    Loop

    'Release objects from memory.
    Set noNextDocument = Nothing
    Set noDocument = Nothing
    Set noView = Nothing
    Set noDatabase = Nothing
    Set noSession = Nothing

    MsgBox "All the attachments in the Inbox have successfully been saved and removed." _
    , vbInformation

    'Clean Up
    err_h:
    Set noSession = Nothing
    Set noDatabase = Nothing
    Set noDocument = Nothing
    Set noNextDocument = Nothing
    Set noView = Nothing
    End Sub

    [/vba]



    Thanks Kenneth.

    I tried this code but facing the same problem...it successfully detach attachment, delete attachment, create copy of mail in 'Processed' LN folder but never delete original mail from inbox. Again it create linked mails (copy mail of 'Processed' folder and original mail of inbox are linked, you delete from one place they get deleted from both place).
    I thought it could be some refresh problem but thats also not the problem. Now this is making me crazy....

  14. #14
    Hi Shrivallabha,

    I am still stuck with this ....any suggestion please.

  15. #15
    Try this. It works for me on Notes 6.5.5. As I suggested, it uses the Domino COM class NotesSession to establish a Notes session:

    Set NSession = CreateObject("Lotus.NotesSession")
    [vba]Private Const RICHTEXT As Long = 1
    Private Const EMBED_ATTACHMENT As Long = 1454


    Public Sub Save_and_Remove_File_Attachments_Move_Folder()

    Dim NUIWorkspace As Object
    Dim NSession As Object
    Dim NMailDb As Object
    Dim NMoveDocsCollection As Object
    Dim NView As Object
    Dim NDoc As Object, NNextDoc As Object
    Dim NItem As Variant
    Dim NAttachment As Variant
    Dim NMailDoc As Object
    Dim sSendTo As String
    Dim sSubject As String
    Dim sAttachmentNames As String
    Dim sSaveWindowsFolder As String
    Dim sUserDB As String, sServerName As String, sNotesSourceFolder As String, sNotesDestinationFolder
    Dim sBodyText As String

    sNotesSourceFolder = "$Inbox"
    sNotesDestinationFolder = "Processed"
    sSaveWindowsFolder = "C:\MailDocs\"
    sServerName = "" 'local Notes server - change as required
    sUserDB = "mailnsf"

    sBodyText = "Thank you for your mail."

    'Front end UI is only exposed with OLE automation

    Set NUIWorkspace = CreateObject("Notes.NotesUIWorkspace")

    'Start a Notes session, using Lotus Domino Objects (COM classes)

    Set NSession = CreateObject("Lotus.NotesSession") 'COM, late binding
    NSession.Initialize "" 'supported in COM only

    Set NMailDb = NSession.GETDATABASE(sServerName, sUserDB)
    If Not NMailDb.IsOpen Then NMailDb.Open

    'Create an empty collection which will contain the documents to be moved from the Notes source folder to the destination folder
    'This is a kludge because Notes can't do: Set docCollection = New NotesDocumentCollection

    Set NMoveDocsCollection = NMailDb.Search("", Nothing, 0)

    'Loop through all documents in source folder

    Set NView = NMailDb.GetView(sNotesSourceFolder)
    Set NDoc = NView.GetFirstDocument
    Do Until NDoc Is Nothing

    'Cache next document in case the view changes outside this procedure

    Set NNextDoc = NView.GetNextDocument(NDoc)

    'Has current document got an attachment?

    If NDoc.HasEmbedded Then
    Set NItem = NDoc.GetFirstItem("Body")
    If NItem.Type = RICHTEXT Then

    sSendTo = NDoc.GetItemValue("From")(0)
    sSubject = NDoc.GetItemValue("Subject")(0)

    Debug.Print "Move: " & sSubject

    'Save and remove each attachment

    sAttachmentNames = ""
    For Each NAttachment In NItem.EmbeddedObjects
    If NAttachment.Type = EMBED_ATTACHMENT Then
    sAttachmentNames = sAttachmentNames & NAttachment.Name & ", "
    ExtractNotesAttachment NAttachment, sSaveWindowsFolder
    NAttachment.Remove
    End If
    Next

    'Save the modified document and add it to the collection of documents to be moved

    NDoc.Save True, False
    NMoveDocsCollection.AddDocument NDoc

    'Create and send email to sender

    Set NMailDoc = NMailDb.CreateDocument
    With NMailDoc
    .ReplaceItemValue "Form", "Memo"
    .ReplaceItemValue "Subject", "Re: " & sSubject & " - " & Left(sAttachmentNames, Len(sAttachmentNames) - 2)
    .ReplaceItemValue "SendTo", sSendTo
    .ReplaceItemValue "Body", sBodyText

    'The Principal and From fields are required, otherwise the From email address is empty in the received email.
    'Note that the @MyNotesDomain string must be present in the Principal field

    .ReplaceItemValue "Principal", "Your Name<your.email_address@email.com@YourNotesDomain>" 'CHANGE AS REQUIRED
    .ReplaceItemValue "From", "Your Name<your.email_address@email.com>" 'CHANGE AS REQUIRED

    .SaveMessageOnSend = True
    .Send False
    End With

    End If
    End If

    Set NDoc = NNextDoc

    Loop

    'Move documents from Notes source folder to destination folder

    With NMoveDocsCollection
    .PutAllInFolder sNotesDestinationFolder, True
    .RemoveAllFromFolder sNotesSourceFolder
    End With

    'Refresh source folder

    NUIWorkspace.VIEWREFRESH

    Set NMailDoc = Nothing
    Set NNextDoc = Nothing
    Set NDoc = Nothing
    Set NMoveDocsCollection = Nothing
    Set NView = Nothing
    Set NMailDb = Nothing
    Set NSession = Nothing
    Set NUIWorkspace = Nothing

    End Sub

    Private Sub ExtractNotesAttachment(NotesAttachment As Variant, WindowsFolder As String)

    'Extract a Notes file attachment to a Windows folder path

    'The ExtractFile method can cause the following error:
    ' Notes error: File is in use by another program

    'Therefore we isolate this method in this procedure to handle this possible error by waiting
    'and trying again until successful

    On Error Resume Next
    Do
    Err.Clear
    NotesAttachment.ExtractFile WindowsFolder & NotesAttachment.Name

    If Err.Number <> 0 Then
    'Debugging info only
    Debug.Print "Err.Number = " & Err.Number
    Debug.Print "Err.Description = " & Err.Description
    Debug.Print "Err.LastDllError = " & Err.LastDllError
    End If

    If Err.Number <> 0 Then Application.Wait Now + TimeValue("00:00:00.20")
    Loop Until Err.Number = 0
    On Error GoTo 0

    End Sub
    [/vba]A word or two on some of the techniques used.

    I found that moving documents one by one caused documents to be skipped. Therefore instead of moving each document in the loop, it adds them to a collection which is moved as a whole outside the loop.

    Another 'gotcha' is that sometimes the ExtractFile method can cause the following error:

    Notes error: File is in use by another program.

    This potential error is handled by calling ExtractFile in a separate procedure which contains an On Error handler which waits and tries again until the file is successfully extracted. This error probably occurred in my testing because all my test documents (emails) have the same file attachments and it's possible that the Windows disk i/o was still busy saving the file for the previous Notes document file when it tried to save the same file for the next Notes document.
    Last edited by Crocus Crow; 06-02-2011 at 07:04 AM.

  16. #16

    Smile Thanks thanks and thanks

    Crocus Crow Thank a million

    Thanks to Kenneth and Shrivallabha for all their help.

    I have been looking for answer everywhere and finallllllly.......

    I love this forum.

  17. #17

    Answer to why item gets deleted from both folders...

    (I know this issue was answered a year back, but this is background info on Lotus Notes behaviour)

    I found this thread while looking for info on Lotus Notes' object model for a bit of access from VBA and scripting tools. I've used Notes for ages

    The way Notes uses folders means that a document (email etc) can be in more than one folder. It's not like a disk file being in only one folder by definition, it's more like tagging a message in a blog or on twitter, where several tags can be relevant. Think cross-references and you start to get the idea.

    So simply putting a document into a folder doesn't move it out of where it is. And the Inbox is a folder in Notes's terms. Equally, deleting a document that's in the Inbox does what it says on the tin: it deletes the document from the database, so it disappears from both Inbox and wherever else it is (""Cleared" in this example).

    What you have to do is put the document into your target folder and then use "remove from folder" to stop it appearing in the Inbox. In the Notes user interface, there is a "move to folder" option which does indeed do both operations in one click - but I don't know whether that is available from VBA. I suspect it isn't in order to give programmer control and because it would only be one extra statement to code.

    Hope that's interesting & useful. Now back to my problem...

  18. #18
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Hi duncanphilips,

    Thanks for sharing LN related info. That said, you haven't specified what are you setting out to do?

    If you are looking for good reference regarding Lotus objects then try IBM Redbook. And listen to what crocus_crow has suggested above. I have tried to summarize my experience here.

    Apart from this, if you want to work out some mail sending routines then see Ron De Bruin's site which has good reference material in this regard.

    If your requirement is different than WhySoSerious' then it will be wise to start a new thread. Good Luck.
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

Posting Permissions

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