VBA excel任命为草稿

VBA excel任命为草稿,excel,vba,outlook,appointment,Excel,Vba,Outlook,Appointment,好吧,所以我不是开发者。我知道的足以让自己陷入困境。我有一个excel vba,它从电子表格中获取数据,然后向团队成员和客户发送outlook日历邀请。它确实工作正常(可以这么说…),但它总是保持草稿,在to:字段或主题中没有联系人。这是我的代码的问题,还是outlook的问题 。。。可能还需要清理声明 Dim olApp As Outlook.Application Dim olEmail As Outlook.MailItem Dim olCal As Outlook.Appointment

好吧,所以我不是开发者。我知道的足以让自己陷入困境。我有一个excel vba,它从电子表格中获取数据,然后向团队成员和客户发送outlook日历邀请。它确实工作正常(可以这么说…),但它总是保持草稿,在to:字段或主题中没有联系人。这是我的代码的问题,还是outlook的问题

。。。可能还需要清理声明

Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Dim olCal As Outlook.AppointmentItem
Dim olFolder As Outlook.Folder
Dim RequiredAttendee, OptionalAttendee, ResourceAttendee As Outlook.Recipient
Dim rtf() As Byte

Dim objOutlook As Object, objnSpace As Object, objFolder As MAPIFolder
Dim rngTo As Range
Dim rngCC As Range
Dim rngSUB As Range
Dim rngCALloc As Range
Dim rngCALstart As Range
Dim rngCALend As Range
Dim rngBody As Range
Dim myItem As Object

Dim oApp As Object
Dim oNameSpace As Namespace
Dim oFolder As Object

Sub SVN()
'Creates Outlook Calendar Site Visit Notification for one day onsite.'
    Set olApp = New Outlook.Application
    Set m = olApp.CreateItem(olMailItem)
    Set appt = olApp.CreateItem(olAppointmentItem)

    With ActiveSheet
        Set rngTo = .Range("J3")
        Set rngCC = .Range("J4")
        Set rngCALloc = .Range("J5")
        Set rngCALstart = .Range("J7")
        Set rngCALend = .Range("J8")
        Set rngSUB = .Range("J14")
    End With

    MsgBox "Verify Attendees:  Customer, Sales, Service."

        appt.MeetingStatus = olMeeting
        appt.RequiredAttendees = rngTo.Value
        appt.OptionalAttendees = rngCC.Value
        appt.Subject = rngSUB.Value
        appt.Location = rngCALloc.Value

        appt.Start = rngCALstart.Value
        appt.End = rngCALend.Value
        appt.AllDayEvent = True

        m.BodyFormat = olFormatHTML
        m.HTMLBody = Range("J16").Value
        m.GetInspector().WordEditor.Range.FormattedText.Copy
        appt.GetInspector().WordEditor.Range.FormattedText.Paste
        appt.Display

End Sub

您正在有效地创建一个邮件项目,以格式化电子表格中的文本,并将其复制/粘贴到约会中,然后再也不关闭该邮件项目。请参见下面的注释代码

最简单的解决方案可能是在末尾添加
m.Close olDiscard
。更“有效”的解决方案是删除只为将文本格式化为约会而创建邮件的逻辑

Sub SVN()
'Creates Outlook Calendar Site Visit Notification for one day onsite.'
    Set olApp = New Outlook.Application
    Set m = olApp.CreateItem(olMailItem) '<--------------Make new mail item
    Set appt = olApp.CreateItem(olAppointmentItem)

    With ActiveSheet
        Set rngTo = .Range("J3")
        Set rngCC = .Range("J4")
        Set rngCALloc = .Range("J5")
        Set rngCALstart = .Range("J7")
        Set rngCALend = .Range("J8")
        Set rngSUB = .Range("J14")
    End With

    MsgBox "Verify Attendees:  Customer, Sales, Service."

        appt.MeetingStatus = olMeeting
        appt.RequiredAttendees = rngTo.Value
        appt.OptionalAttendees = rngCC.Value
        appt.Subject = rngSUB.Value
        appt.Location = rngCALloc.Value

        appt.Start = rngCALstart.Value
        appt.End = rngCALend.Value
        appt.AllDayEvent = True

        m.BodyFormat = olFormatHTML '<-----------Adjust new mail item bodyformat to HTML
        m.HTMLBody = Range("J16").Value '<-------Paste data from spreadsheet into mail item
        m.GetInspector().WordEditor.Range.FormattedText.Copy '<-----Copy the formatted text from mail item
        appt.GetInspector().WordEditor.Range.FormattedText.Paste '<----Paste into the appointment.
        m.Close olDiscard '<----This is new. Close the mail item and discard (no save)
        appt.Display


End Sub
Sub SVN()
'在现场创建一天的Outlook日历站点访问通知。'
Set olApp=newoutlook.Application

将m=olApp.CreateItem(olMailItem)'FYI-
Dim RequiredAttendee、OptionalAttendee、ResourceAttendee设置为Outlook.Recipient
。只有
ResourceAttendee
必须是
Outlook.Recipient
。其他变量是
Variant
…您需要显式声明所有变量类型,否则它们默认为
Variant
。(这可能不是问题所在,我只是想指出。)