在VBscript中拆分GetNameSpace(“MAPI”)的输出

时间:2017-07-22 02:31:01

标签: vbscript

我正在学习VBscript以帮助在outlook中创建用户表单。使用此约会表单,我正在尝试使用当前用户的名称创建预先格式化的电子邮件。我只希望输出成为当前用户的名字。它目前正在返回全名。

如何拆分用户名或仅获取用户名?

提前致谢。

Sub commandbutton1_click()
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0) 'olMailItem
set prop = item.userproperties.find("Mobile")
set currentuser = application.getNameSpace("MAPI").CurrentUser
Set prop1 = item.userProperties.find("Subject")
Set prop2 = item.userProperties.find("Location")
Set prop3 = item.userProperties.find("DateStart")

dteThen = dateAdd("h", -1, Now())

With MyItem
                .To = prop & "@etxt.co.nz"
                .Subject = ""
                .Body = "Hi " & Subject & vbCrlf & vbCrlf & "This is a reminder about your meeting at " & Location & vbCrlf & vbCrlf & "Thanks" & currentUser
                .DeferredDeliveryTime = DateStart + dteThen
End With
MyItem.Display
end sub

1 个答案:

答案 0 :(得分:0)

相当简单......

Sub commandbutton1_click()
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0) 'olMailItem
set prop = item.userproperties.find("Mobile")
set currentuser = application.getNameSpace("MAPI").CurrentUser
Set prop1 = item.userProperties.find("Subject")
Set prop2 = item.userProperties.find("Location")
Set prop3 = item.userProperties.find("DateStart")
arrUserName = Split(currentUser, ",") 'Split the name using "," 
strName = Trim(arrUserName(1))   'Remove any space

dteThen = dateAdd("h", -1, Now())

With MyItem
                .To = prop & "@etxt.co.nz"
                .Subject = ""

                .Body = "Hi " & Subject & vbCrlf & vbCrlf & "This is a reminder about your meeting at " & Location & vbCrlf & vbCrlf & "Thanks," & vbcrLF & strName 'use of strName
                .DeferredDeliveryTime = DateStart + dteThen
End With
MyItem.Display
end sub