我创建了一个宏,它将从 LDAP 中提取信息并通过 Word 文档中的书签将其插入。这完美地工作,除非属性为空。因此,在 Word 文档中,标题插入到用户名之前,但是当用户没有标题时,脚本会停止并给出错误消息。如果 AD 中的属性为空,如何使脚本跳过该函数?
这是部分脚本,当用户没有标题时它会停止(最后):
Sub AutoNew()
With ActiveDocument.Bookmarks("MyTitle").Range
.InsertBefore GetTitle
End With
With ActiveDocument.Bookmarks("MygivenName").Range
.InsertBefore GetgivenName
End With
With ActiveDocument.Bookmarks("Mysn").Range
.InsertBefore Getsn
End With
With ActiveDocument.Bookmarks("MytelephoneNumber").Range
.InsertBefore GettelephoneNumber
End With
With ActiveDocument.Bookmarks("Mymail").Range
.InsertBefore Getmail
End With
End Sub
Function GetTitle() As String
Dim objSysinfo As Object
Dim objUser As Object
Dim strUser As String 'Distinguished Name
Set objSysinfo = CreateObject("ADSystemInfo")
strUser = objSysinfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
GetTitle = objUser.get("Title")
End Function
如果有人可以帮助我,我会很高兴。干杯,索尼娅