通过Excel按钮制作Outlook任务项 [英] Make Outlook Task item through Excel Button

查看:143
本文介绍了通过Excel按钮制作Outlook任务项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个简单的程序,可以在其中创建Outlook任务.用户填写数据并单击创建按钮.

I want to make a simple program in which I can create an Outlook Task. User fills in data and clicks the create button.

我在线找到了以下代码,它应该可以工作,但不能.我的Outlook中未添加任何任务,但也未显示任何错误.我觉得添加任务的接收者以某种方式出错.

I found the following code online and it should work, but it doesn't. No task is added in my Outlook, but no error is shown either. I have the feeling it somehow goes wrong with adding the recipients of the task.

任何提示为什么我没有收到错误消息,但是没有添加任何任务吗?

Any clue why I don't get an error but, no tasks are added?

Dim OutApp As Outlook.Application
Dim OutTask As Outlook.TaskItem


Set OutApp = CreateObject("Outlook.Application")
Set OutTask = OutApp.CreateItem(olTaskItem)
Set myRecipient = OutTask.Recipients.Add("I.wont.write.my.actual.address.in.this@example.com")
myRecipient.Type = olTo



 If myRecipient.Resolved Then
    With OutTask
    .Display
       .Subject = Cells(3, "I")
       .StartDate = Now
       .DueDate = Cells(2, "I")
       .Body = "Please see the attached email for a service request assigned to you."
    End With
End If
Set OutTask = Nothing
Set OutApp = Nothing

我只是想不通,此刻确实在伤脑筋.希望有人可以向我提示正确的方向!

I just can't figure it out and it's really breaking my brain at the moment. Hope someone can hint me in the right direction!

推荐答案

我在线找到了以下代码,它应该可以工作,但不能.我的Outlook中未添加任何任务,但也未显示任何错误.我觉得添加任务的接收者以某种方式出错.

I found the following code online and it should work, but it doesn't. No task is added in my Outlook, but no error is shown either. I have the feeling it somehow goes wrong with adding the recipients of the task.

正确-尝试 收件人 对象myRecipient.Resolve相对于通讯簿,然后假定其解析的If myRecipient.Resolved Then也为myRecipient

Correct - Attempt to resolve the Recipient object myRecipient.Resolve against the Address Book before assuming its resolved If myRecipient.Resolved Then also defined variable Dim myRecipient As Outlook.Recipient for myRecipient

Option Explicit
Sub tasks()
    Dim OutApp As Outlook.Application
    Set OutApp = CreateObject("Outlook.Application")

    Dim OutTask As Outlook.TaskItem
    Set OutTask = OutApp.CreateItem(olTaskItem)

    Dim myRecipient As Outlook.Recipient
    Set myRecipient = OutTask.Recipients.Add("0m3r@Email.com")
        myRecipient.Type = olTo
        myRecipient.Resolve

     If myRecipient.Resolved Then
        With OutTask
        .Display
           .Subject = Cells(3, "I")
           .StartDate = Now
           .DueDate = Cells(2, "I")
           .Body = "Please see the attached email."
        End With
    End If

    Set OutTask = Nothing
    Set OutApp = Nothing
End Sub

期权明确声明(Visual Basic)

强制文件中所有变量的显式声明,或允许变量的隐式声明.

这篇关于通过Excel按钮制作Outlook任务项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆