繁体   English   中英

VBA在莲花笔记中离开办公室

[英]VBA set out of office in lotus notes

我试图在Excel中使用vba在Lotus Notes 8.5中设置办公室,很遗憾,它不起作用。 我在此讨论中通过在服务器代理上运行外出服务激活激活找到了代码,得到了“ OutOfOfficeProfile”,但是尝试设置第一天的出行时间后,我得到了错误。 我花了很多时间,但找不到解决问题的方法。

我使用的代码是:

Private Function check(text)
    check = False
    If Err.Number <> 0 Then
        logError text & ": " & Err.Number & ", " & Err.Description & " has occurred at " & Err.Source
        Err.clear
        check = True
    End If
End Function

Private Function create_mail_database_name(user_name)
    create_mail_database_name = Left$(user_name, 1) & Right$(user_name, (Len(user_name) - InStr(1, user_name, " "))) & ".nsf"
End Function

Private Function activate_out_of_office()
    check "activate_out_of_office start"
    On Error Resume Next

    Dim notes_session As Object: Set notes_session = CreateObject("Notes.NotesSession")
Dim user_name As String: user_name = current_user_name
Dim mail_database_name As String: mail_database_name = create_mail_database_name(user_name)

Dim notes_database As Object: Set notes_database = notes_session.CurrentDatabase
check "after mail_database"

Dim profile_document As Object: Set profile_document = notes_database.GetProfileDocument("OutOfOfficeProfile")
check "after profile document"

profile_document.FirstDayOut = "17.12.2015"
check "after profile_document.firstdayout"
profile_document.StartTime = "00:00:00"
check "after start time"

profile_document.FirstDayBack = "27.12.2015"
check "after first day back"
profile_document.EndTime = "00:00:00"
check "after end time "

profile_document.CurrentStatus = "1"
check "after current status"

profile_document.GeneralSubject = "HE IS NOT AVAILABLE"
profile_document.GeneralMessage = "general message"
check "after general subject"

Call profile_document.computeWithForm(False, False)
Call profile_document.Save(True, False)
check "after save"

Dim DBOPT_OUTOFOFFICEENABLED As Integer: DBOPT_OUTOFOFFICEENABLED = 74
Call notes_database.SetOption(74, True)
check "after activate"

    check "activate_out_of_office end"
End Function

我得到的失败是:

  • 概要文件:438之后,VBAProject上发生了未完成的工作
  • 在profile_document.firstdayout:91之后,在VBAProject上发生了对象变量与块变量变量
  • activate_out_of_office_end_normal_58981,79:91,在VBAProject中发生了对象可变变量带块可变的时间节节

首先:发布的代码不完整。 缺少函数current_user_namecreate_mail_database_name

第二:在大多数情况下,用于获取用户邮件文件的服务器名不为空,您需要以某种方式填充它。

第三:这两个将使mail_database成为“本地计算机上的随机数据库”(充其量,可能已经引起了错误)。

没有“正确的”数据库, mail_database.Getprofiledocument("OutOfOfficeProfile")将失败,因此尝试读取该文档的属性将导致无效的结果。

尝试将Dim mail_database As Object: Set mail_database = notes_session.Getdatabase("", mail_database_name)替换Dim mail_database As Object: Set mail_database = notes_session.Getdatabase("", mail_database_name)用这两行Dim mail_database As Object: Set mail_database = notes_session.Getdatabase("", mail_database_name) ,它将起作用:

Dim mail_database As Object
Set mail_database = notes_session.Getdatabase("", "")
Call mail_database.OpenMail()

但是,由于您不想为此使用适当的功能,因此放开其他“ Dos”和“ Donts”:让代码说“ On Error Resume Next实际上是最糟糕的做法:您需要捕获错误并停止执行。 将此行替换为On Error goto ErrorHandler并在代码末尾添加以下代码行:

  Exit Function
ErrorHandler:
  MsgBox Err.Number & " - " & Err.Description & " in line " & Erl

这样,您可以捕获发生的FIRST错误,尽管不可能,但不要尝试继续。

现在,您可以调试代码了。

如果您的代码确实返回了用户的邮件文件(可能,但要取决于运气),则第一个错误将出现在Set profile_document.FirstDayOut = leaving_date

由于FirstDayOut不是对象,而是简单的数组,因此不应在此处使用Set: profile_document.FirstDayOut = leaving_date就足够了。

现在继续调试,您可能会得到有效的代码...

暂无
暂无

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

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