如何用vba代码刷新莲花笔记?

时间:2014-08-07 04:43:33

标签: excel vba excel-vba lotus-notes

我有一个vba代码,可以从lotus notes下载附件,并将电子邮件标记为已读。但问题是UI无法刷新自己。即使文件已下载,它也会在UI中显示未读。我怎么能纠正这个?

代码:

Option Explicit
Dim TimeToRun
Public RunWhen As Double
Const cRunInvtSecs = 5
Const cRunWhat = "Sheet1.Save_Attachments_Remove_Emails"
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunInvtSecs)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True
'Call Save_Attachments_Remove_Emails

End Sub
Sub Save_Attachments_Remove_Emails()
'MsgBox ("Hello 2")
Const stPath As String = "C:\ZipLogs\"
Const EMBED_ATTACHMENT As Long = 1454
Const RICHTEXT As Long = 1

Dim noSession As Object
Dim noDatabase As Object
Dim noView As Object
Dim noDocument As Object
 Dim noRemoveDocument As Object
 Dim noNextDocument As Object

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

'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.)
'I have deleted the server name and database,(for security reasons), But the database is not on local system,it is on server.
 Set noDatabase = noSession.GETDATABASE("","")
' Please use this Open Function if the server is not referenced and GETDATABASE
' opens the db file if the file is in local system.
'Call noDatabase.Open("", "C:\notes\test.nsf")

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

'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
Set noNextDocument = noView.GetNextDocument(noDocument)
Dim flag As Boolean
    flag = noDocument.GetRead
    'Call noDocument.MarkRead
If flag = False Then
'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.
        vaAttachment.ExtractFile stPath & vaAttachment.Name
        'Set the e-mail object which will be deleted.
      '  Set noRemoveDocument = noDocument


      Call noDocument.MarkRead
      Call noView.Refresh

      End If

    Next vaAttachment
  End If
End If
End If


Set noDocument = noNextDocument
'Delete the e-mails which have an attached file.
' If Not noRemoveDocument Is Nothing Then
 ' noRemoveDocument.Remove (True)
 ' Set noRemoveDocument = Nothing
'End If
Loop

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

Call StartTimer
End Sub


Sub auto_close()
Application.OnTime TimeToRun, "Save_Attachments_Remove_Emails", , False

End Sub

2 个答案:

答案 0 :(得分:0)

您的数据库是否跟踪未读标记?

我认为你的代码在后台运行莲花。

Mayby你应该尝试使用Lotus uiview吗?并在Lotus Designer上编写代码?

来自帮助:

在视图上创建按钮和..(修改下面的代码以查找兴趣文档)

此表单操作会保存当前文档,刷新视图(称为“Main”)并关闭文档。

Sub Click(Source As Button)
 ' Declare all variables
 Dim workspace As New NotesUIWorkspace
 Dim session As New NotesSession
 Dim uidoc As NotesUIDocument
 Dim view As NotesView
 Dim db As NotesDatabase
 'Set all variables
 Set uidoc = workspace.CurrentDocument
 Set db = session.CurrentDatabase
 Set view = db.GetView( "Main" )
 'Save current document, refresh "Main" view
 'and close document
 Call uidoc.Save
 Call view.Refresh
 Call workspace.ViewRefresh
 Call uidoc.Close
End Sub

或mayby你没有莲花设计师,你必须在excel中做到这一点吗?

最好的。

答案 1 :(得分:0)

您可以尝试使用lotusscript版本的代码并查看结果。 API在LS中的使用比COM更多,在前者中更依赖。 尝试方法中的用户名参数。 调用notesDocument .MarkRead([username]) 如果它在LS中工作,您可以在笔记中运行它,或者如果需要,可以将其称为代理。