email - 如果请求 AD 字段为空,我如何不打印字符串
问题描述
我编写了一个脚本来查询我们的域控制器 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
解决方案
删除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
推荐阅读
- python - 计算python中列表中过零的数量
- mongoose - 使用 mongoose populate 填充作为 Id 数组的属性
- javascript - How to utilize a while loop to animate and display a total
- javascript - 为什么我的叠加层在 img 悬停时不起作用?
- batch-file - 在 .bat 文件中执行 exiftool 命令
- python - 在单独的类中使用枚举
- sql - 添加日期范围过滤器 - SQL 查询
- c++ - 为什么 std::gcd/lcm 返回 std::common_type_t
而不是汽车? - julia - 如何在 Julia 中重复字符串中的单个字符
- java - 单击JButton时如何更改JLabel?