我编写了一个查询域控制器AD的脚本,并提取了数据以创建电子邮件签名,由于以前没有使用这种语言的经验,因此我在网上使用了大量教程来完成此操作。
除一个字段外,其他所有内容都可以正常运行;手机。
仅当该字段包含任何数据时,我才想打印一行,但是我不知道该怎么做。我敢肯定这是一个简单的解决方案,但我正在画一个完整的空白。
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
' ########### This section connects to Active Directory as the currently logged on user
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strUKPhone = "+44 (0)20 3457 7633"
strUKMobile = objUser.mobile
strEmail = objuser.mail
strWeb = objuser.wWWHomePage
strNotes = objuser.info
strExt = objuser.ipPhone
strDDI = objuser.homephone
strSALUTATION = "Kind regards,"
strEmailTEXT = "E "
strWebTEXT = "W "
strAddressTEXT = "A "
strPhoneTEXT = "T "
strMobileTEXT = "M "
' ########### Sets up word template
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.Style = "No Spacing"
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
' ########### Calls the variables from above section and inserts into word template, also sets initial font typeface, colour etc.
objselection.TypeText strEmailTEXT
objSelection.Font.Color = RGB (000,000,000)
objselection.Font.Bold = false
Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, "mailto: " & strEmail, , , strEmail)
objLink.Range.Font.Name = "Arial"
objLink.Range.Font.Size = 8.5
objLink.Range.Font.Bold = false
objSelection.Font.Color = RGB (000,000,000)
objSelection.TypeText " | "
objSelection.Font.Color = RGB (181,021,059)
objSelection.TypeText strMobileTEXT
objSelection.Font.Color = RGB (000,000,000)
objSelection.TypeText strUKMobile
objSelection.TypeParagraph()
objSelection.Font.Color = RGB (181,021,059)
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Email Signature", objSelection
objSignatureObject.NewMessageSignature = "Email Signature"
objSignatureObject.ReplyMessageSignature = "Email Signature"
Set objSelection = objDoc.Range()
objDoc.Saved = True
objWord.Quit
答案 0 :(得分:0)
删除行strUKMobile = objUser.mobile
所在的行以及构建文本的部分,执行以下操作:
objselection.TypeText strEmailTEXT
objSelection.Font.Color = RGB (000,000,000)
objselection.Font.Bold = false
Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, "mailto: " & strEmail, , , strEmail)
objLink.Range.Font.Name = "Arial"
objLink.Range.Font.Size = 8.5
objLink.Range.Font.Bold = false
objSelection.Font.Color = RGB (000,000,000)
' Only write this if the mobile phone has a value
If Not (IsNull(objUser.mobile) Or IsEmpty(objUser.mobile)) Then
strUKMobile = objUser.mobile
objSelection.TypeText " | "
objSelection.Font.Color = RGB (181,021,059)
objSelection.TypeText strMobileTEXT
objSelection.Font.Color = RGB (000,000,000)
objSelection.TypeText strUKMobile
objSelection.TypeParagraph()
objSelection.Font.Color = RGB (181,021,059)
End If