VB、VBS和VBA中使用outlook学习(一)

一、初识「Outlook.Application对象的使用

演示如何在vb中创建一个新outlook任务

'---------------------------------------------------------------------
'演示如何创建一个新任务
'---------------------------------------------------------------------

Dim xOutLook As New Outlook.Application
Dim xMail As MailItem

Dim SUBJECT_MATTER As String
Dim PLACE As String
Dim START_TIME As String
Dim DURATION_MINUTES As Long
Dim MINUTES_BEFORE_START As Long
Dim BODY_TEXT


Private Sub Command1_Click()
    '创建一个新任务
    Set objTaskItem = xOutLook.CreateItem(ItemType:=olTaskItem)

    With objTaskItem
        .Subject = SUBJECT_MATTER
        '.Location = PLACE
        .StartDate = START_TIME
        '.Duration = DURATION_MINUTES
        '.ReminderMinutesBeforeStart = MINUTES_BEFORE_START
        '.BusyStatus = olOutOfOffice
        .Body = BODY_TEXT
        .Sensitivity = olPrivate
        .Save
        .Display
    End With
End Sub

Private Sub Form_Load()
    SUBJECT_MATTER = "午餐会"
    PLACE = "Championzone 餐厅"
    START_TIME = #8/13/2001 6:00:00 PM#
    DURATION_MINUTES = 90
    MINUTES_BEFORE_START = 45
    BODY_TEXT = "别忘记带礼物!"
End Sub

Private Sub Form_Unload(Cancel As Integer)
    '退出Outlook
    'xOutLook.Quit
    Set xMail = Nothing
    Set xOutLook = Nothing
End Sub

Private Sub List1_Click()
    'Text1.Text = List1.List(List1.ListIndex)
End Sub
 

操作olMailItem的例子:创建邮件信息文件 

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Item.Categories = ""
    If Item.Class = olMail Then
        Call CheckToSave(Item)
    End If
End Sub

Public Sub CheckToSave(objMail As MailItem)
    Dim Msg, Style, Title, Response, MyString, strSaveName
    Msg = "Do you want to save a copy of this email to file?"    ' Define message.
    Style = vbYesNo + vbQuestion + vbDefaultButton1    ' Define buttons.
    Title = "Mailbox Control"    ' Define title.
    strSaveName = "C:/Temp/MySavedMessage.txt" 'Change this to change the path and name of the file.
       
        ' Display message.
    Response = MsgBox(Msg, Style, Title)

    If Response = vbYes Then    ' User chose Yes.
        objMail.SaveAs strSaveName, olTXT
    Else    ' User chose No.
   
    End If
End Sub

Private Sub Command2_Click()
    Set xMail = xOutLook.CreateItem(ItemType:=olMailItem)
    With xMail
        xMail.To = Text1.Text
        xMail.Subject = Text2.Text
        xMail.Body = Text3.Text
    End With

    Call Application_ItemSend(xMail, True)
End Sub 

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值