Vba 从Excel发送值时在Outlook邮件中以小时:分钟格式保留时间

Vba 从Excel发送值时在Outlook邮件中以小时:分钟格式保留时间,vba,excel,outlook,Vba,Excel,Outlook,发送到Outlook电子邮件时,小时:分钟的时间格式将更改为数字,例如..463 Private Sub CommandButton1_Click() Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) EndDate = ActiveCell.Value With OutMail .To = "Enter Specific con

发送到Outlook电子邮件时,小时:分钟的时间格式将更改为数字,例如..463

Private Sub CommandButton1_Click()
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
EndDate = ActiveCell.Value
With OutMail
    .To = "Enter Specific contact email address"
    .CC = ""
    .BCC = ""
    .Subject = "Enter subject, along the lines of Reminder, due to end etc."
    .body = EndDate
    .Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

您只需要更改主体以获得所需的格式。请看下面:

.body = Format(EndDate, "HH:MM")
这是唯一需要改变的事情。有关其他可用格式,如
“HH:MM AMPM”
,请参阅

附言


@ScottCraner提出的(
EndDate=ActiveCell.Text
)也能奏效。但我个人更喜欢第一种解决方案,因为它使您能够在必要时对
EndDate
变量执行计算。

ActiveCell.Value
更改为
ActiveCell.Text
。这与您之前的问题完全相同。我已经标记过了。但请避免这样做。