我一点都不熟悉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编辑器,并将该代码粘贴到模块或ThisWorkBook中
添加对Microsoft Outlook对象库的引用(工具,参考...)。 Excel与Outlook交互(创建邮件和约会项等)需要此选项。
添加一个按钮以运行该过程(我假设您在功能区上显示了Developer选项卡。单击它,然后插入,选择一个表单控件按钮,将其放置在工作表上。右键单击并单击Assign Macro。选择您的列表中的宏。单击确定。
然后单击按钮将运行该过程。
它对我有用,但只有在注释掉涉及电子表格范围(我没有)的行之后。另外,对于约会属性(开始,结束,正文等),我给了他们一些化妆日期和信息,以使其高兴。