0
votes

I have a script (found on the web and adjusted to my needs) that can access a specific view of Lotus Notes, pick up some info from each email and save any attachment to a given folder. If I want to do this for more views I currently have the names of these views in my worksheet and loop through them. What I would like to do is to loop through all views and do the same.

I am not a professional developer and not yet entirely familiar working with objects. This problem however is to complicated for me. The Lotus Notes object is also not the easiest to understand.

I am using the following code which of course is part of a larger (working) script. For starters it would be enough to just be able to loop through all views and print the Name of the view. From there on I think I can do the rest myself. Can anyone adjust the code to make it work.

Public Sub Get_Notes_Email_Text()

Dim NSession As Object      'NotesSession
Dim NMailDB As Object       'NotesDatabase
Dim NDocs As Object         'NotesDocumentCollection
Dim NDoc As Object          'NotesDocument
Dim NNextDoc As Object      'NotesDocument
Dim view As String

'Start a Lotus Notes session
Set NSession = CreateObject("Notes.NotesSession")
'Connect to the Lotus Notes database
 Set NMailDB = NSession.GetDatabase("", "C:\Users\" & Environ("Username") & "\AppData\Local\IBM\Notes\Data\mail\" & Environ("Username") & ".nsf") 'Default server en database
If Not NMailDB.IsOpen Then
    NMailDB.OpenMail
End If

'Loop through all views and print .Name tot Immediate Window

'    Dim Map As Variant
'    Dim Mappen As Object
'    Set Mappen = NMailDB.Views
'
'    For Each Map In Mappen
'        Debug.Print Map.Name
'    Next Map
'
End Sub
1
All you have shown us here is some commented-out code. We'll be happy to help you debug your code, because that helps you learn. We're a lot less happy to write code for you. So tell us -- what happens when you remove those comments and try to run the code? - Richard Schwartz

1 Answers

0
votes

Easier than going through all views is to just go to one view that shows all documents. If it is a mail database, then the view is called "($All)"

Set allDocsView = NMailDB.getView("($All)")
allDocsView.autoUpdate = false

You can then loop through the documents in the view using

Set docToProcess = allDocsView.GetFirstDocument
While Not ( docToProcess Is Nothing )
    'Do what you plan to do here
Set docToProcess = allDocsView.GetNextDocument( docToProcess )
Wend

UPDATE: As you want to loop through Folders, not views, you need to do something like the following

Dim sess As New notessession
Dim db As NotesDatabase
Dim views As Variant

Set db = sess.CurrentDatabase

views = db.Views
Forall v In views
    If v.isFolder Then ' Needed so that we are only processing Folder objects and not views - you will need to check that you are not processing system folders e.g. $Inbox etc
        'Do your processing of documents here
    End If
End Forall