用于创建outlook任务的Excel文档

用于创建outlook任务的Excel文档,excel,vba,outlook,Excel,Vba,Outlook,我对VBA一点也不熟悉。工作人员创建了一个excel文档,其中有一个按钮可将信息推送到outlook提醒。我很想将其转换为将其推送到outlook任务或创建一个全新的文件,但不知道需要做什么。有人能帮忙吗 我相信这是目前正在使用的代码 Sub Button1_Click() Sheets("Sheet1").Select On Error GoTo Err_Execute Dim olApp As Outlook.Application Dim olAppt A

我对VBA一点也不熟悉。工作人员创建了一个excel文档,其中有一个按钮可将信息推送到outlook提醒。我很想将其转换为将其推送到outlook任务或创建一个全新的文件,但不知道需要做什么。有人能帮忙吗

我相信这是目前正在使用的代码

Sub Button1_Click()

   Sheets("Sheet1").Select
    On Error GoTo Err_Execute

    Dim olApp As Outlook.Application
    Dim olAppt As Outlook.AppointmentItem
    Dim blnCreated As Boolean
    Dim olNs As Outlook.Namespace
    Dim CalFolder As Outlook.MAPIFolder

    Dim i As Long

    On Error Resume Next
    Set olApp = Outlook.Application

    If olApp Is Nothing Then
        Set olApp = Outlook.Application
         blnCreated = True
        Err.Clear
    Else
        blnCreated = False
    End If

    On Error GoTo 0

    Set olNs = olApp.GetNamespace("MAPI")
    Set CalFolder = olNs.GetDefaultFolder(olFolderCalendar)

    i = 12
    Do Until Trim(Cells(i, 1).Value) = ""

    Set olAppt = CalFolder.Items.Add(olAppointmentItem)

    With olAppt

        .Start = Cells(i, 5) + Cells(i, 6)
        .End = Cells(i, 5) + (Cells(i, 6) + TimeSerial(0, 30, 0))
        .Subject = Cells(i, 1)
        .Location = Cells(i, 2)
        .Body = Cells(i, 3)
        .BusyStatus = olBusy
        .ReminderSet = False
        .Save

    End With

        i = i + 1
        Loop
    Set olAppt = Nothing
    Set olApp = Nothing

    MsgBox "The items have been exported to your Outlook Calendar"

    Exit Sub

Err_Execute:
    MsgBox "An error occurred while exporting to your Outlook Calendar"

End Sub

打开VBA编辑器,将代码粘贴到模块或工作簿中

添加对Microsoft Outlook对象库的引用(工具、引用…)。这是Excel与Outlook交互所必需的(创建邮件和约会项目等)

添加一个按钮以运行该过程(我假设功能区上显示了“开发人员”选项卡。单击该按钮,插入,选择一个表单控件按钮,将其放置在工作表上。右键单击并单击“分配宏”。从列表中选择宏。单击“确定”

然后,单击该按钮将运行该过程

这对我来说很管用,但只有在注释掉电子表格上的范围行之后(我没有)。此外,对于约会属性(开始、结束、正文等),我给了他们一些虚构的日期和信息,只是为了让他们开心