获取当前用户 - 签名以交换服务器 - 经理电子邮件地址

时间:2016-02-03 19:51:44

标签: vba excel-vba outlook-vba exchange-server-2010 excel

如何检索当前的用户管理器电子邮件地址? 我只能通过拨打

来获取我的电子邮件地址
  

Application.Session.CurrentUser.AddressEntry.GetExchangeUser

使用

  

Application.Session.CurrentUser.AddressEntry.GetExchangeUser.Manager

什么都不返回...... 我想要实现的是直接从Excel工作表向我的经理发送电子邮件,并在其他用户计算机上自动化(因为他们和其他经理一样)

Sub Mail_workbook_Outlook_1()
    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    If IsEmpty(Range("A21").Value) = True Then ' check if cell is empty
      MsgBox "Cell is empty!", vbCritical, "It would be better to not left it empty..." ' if so, show user a message
    Else

    On Error Resume Next
    With OutMail ' outlook message details
        .To = "xyz@xyz.net"
        .Subject = "Sales report - " & Format(Date, "dd-mm-yyyy")
        .Body = "Here comes the full sales report from " & Format(Date, "dd-mm-yyyy") & Application.Session.CurrentUser.AddressEntry.GetExchangeUser
        .Attachments.Add ActiveWorkbook.FullName ' add current file as an attachment to the outlook message
        .Send
    End With
    On Error GoTo 0
    MsgBox "File sent ", vbInformation, "You can now safely close the report" ' show confirmation message

    Set OutMail = Nothing
    Set OutApp = Nothing
    End If
End Sub

Outlook contact with manager

1 个答案:

答案 0 :(得分:0)

获取当前用户的经理。

上的示例
# Source: local data frame [6 x 9]
# Groups: name [3]
#
#     estimate  statistic   p.value parameter   conf.low conf.high           name       type both_significant
#        (dbl)      (dbl)     (dbl)     (dbl)      (dbl)     (dbl)          (chr)      (chr)            (lgl)
# 1 -0.6593753 -1.1179897 0.8468370         6 -1.8054369       Inf hsa-miR-99a-5p dataTissue             TRUE
# 2 -2.6602026 -4.6508774 0.9982498         6 -3.7716602       Inf hsa-miR-99a-5p  dataSerum             TRUE
# 3  0.3482573  0.6410169 0.2726011         6 -0.7074507       Inf  hsa-miR-93-5p dataTissue            FALSE
# 4 -1.2141093 -2.5674955 0.9787610         6 -2.1329943       Inf  hsa-miR-93-5p  dataSerum            FALSE
# 5  0.2019113  0.2219719 0.4158491         6 -1.5656549       Inf hsa-miR-92b-3p dataTissue            FALSE
# 6 -1.1822187 -1.7248956 0.9323470         6 -2.5140465       Inf hsa-miR-92b-3p  dataSerum            FALSE

修改

请记住,用户必须具有经理设置。

以这种方式修改代码

Option Explicit
Sub GetManager()

    MsgBox CreateObject("Outlook.Application").GetNamespace("MAPI") _
                    .CurrentUser.AddressEntry.GetExchangeUser.Manager

End Sub

另见MSDN示例

How to: Get Availability Information for an Exchange User's Manager