OUTLOOK:SUB mở email template và đổi Subject theo ngày

 Sub OpenTemplate()

    Dim olApp As Object

    Dim olItem As Object

    Dim weekNum As Integer

    Dim reportDate As Date

    Dim subjectDate As String

    

    ' Tạo một thể hiện của ứng dụng Outlook

    Set olApp = CreateObject("Outlook.Application")

    

    ' Tạo một mục email mới từ mẫu đã được định sẵn

    Set olItem = olApp.CreateItemFromTemplate("C:\Users\PKUser\AppData\Roaming\Microsoft\Templates\Daily Report W12.oft")

    

    ' Lấy ngày hiện tại

    reportDate = Date

    

    ' Lấy số tuần trong năm cho ngày hiện tại

    weekNum = DatePart("ww", reportDate, vbMonday)

    

    ' Format ngày thành chuỗi mm/dd/yyyy

    subjectDate = Format(reportDate, "mm/dd/yyyy")

    

    ' Sửa Subject của email

    olItem.Subject = subjectDate & " Daily Report W" & weekNum

    

    ' Hiển thị mục email

    olItem.Display

    

    ' Giải phóng bộ nhớ

    Set olItem = Nothing

    Set olApp = Nothing

End Sub


Nhận xét