繁体   English   中英

如何使用VBA代码刷新Lotus Notes?

[英]How to refresh lotus notes with vba code?

我有一个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

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

我认为您的代码在后台Lotus中工作。

也许您应该尝试在Lotus uiview上工作? 并在Lotus Designer上编写代码?

来自帮助:

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

此表单操作将保存当前文档,刷新视图(称为“主”),然后关闭文档。

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您还没有Lotus设计师,必须在excel中做呢?

一切顺利。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM