Application.CreateItemクリエイトアイテム メソッド

本ページには広告が含まれています。

新しいOutlookのアイテムを表すオブジェクトを作成します。

構文
  1. Object = Application.CreateItem( ItemType )
引数
ItemType 省略可
olitemtypeを指定。以下を参照。
戻り値
olAppointmentItem
AppointmentItem オブジェクト
olContactItem
Outlook.CreateItem
olDistributionListItem
Outlook.CreateItem
olJournalItem
Outlook.CreateItem
olMailItem
MailItem オブジェクト
olMobileItemMMS
Outlook.CreateItem
olMobileItemSMS
Outlook.CreateItem
olNoteItem
Outlook.CreateItem
olPostItem
Outlook.CreateItem
olTaskItem
TaskItem オブジェクト

Application オブジェクトを返すメソッド・プロパティ

Application.CreateItem メソッド
Application.CreateItem メソッド
Outlookアプリケーションの親を表すApplication オブジェクトを返します。

定数一覧

OlItemType 列挙

名前説明
olMailItem0メール
olAppointmentItem1予定表
olContactItem2連絡先
olTaskItem3タスク
olJournalItem4履歴
olNoteItem5メモ
olPostItem6投稿
olDistributionListItem7連絡先グループ
olMobileItemSMS11 SMS
olMobileItemMMS12 MMS
UWSC
CONST olMailItem = 0
CONST olAppointmentItem = 1
CONST olContactItem = 2
CONST olTaskItem = 3
CONST olJournalItem = 4
CONST olNoteItem = 5
CONST olPostItem = 6
CONST olDistributionListItem = 7
CONST olMobileItemSMS = 11
CONST olMobileItemMMS = 12

プログラム実行例

新しいタスクを追加(Outlook)

UWSC
CONST olTaskItem = 3
CONST olImportanceHigh = 2

DIM Outlook = CREATEOLEOBJ("Outlook.Application")
DIM TaskItem = Outlook.CreateItem(olTaskItem)

WITH TaskItem
	// 件名
	.Subject = "件名"
	// 開始日
	.StartDate = "2019/09/07"
	// 期限
	.DueDate = "2019/09/10"
	// アラーム
	.ReminderSet = TRUE
	// アラーム時間
	.ReminderTime = "2019/09/07 09:00:00 PM"
	// 進捗状況
	.Status = 0
	// 優先率
	.Importance = olImportanceHigh
	// 達成率
	.PercentComplete = 90
	// 本文
	.Body = "本文"
	// 保存
	.Save
ENDWITH
使用関数

予定データをExcelから読み込み追加する(Outlook)

[download "/example/625/予定一覧.xlsx"]
UWSC
CONST xlUp = -4162
CONST olAppointmentItem = 1

HASHTBL reminders
reminders["なし"] = -1;       reminders["0分"] = 0;       reminders["5分"] = 5
reminders["10分"] = 10;       reminders["15分"] = 15;     reminders["30分"] = 30
reminders["1時間"] = 60;      reminders["2時間"] = 120;   reminders["3時間"] = 180
reminders["4時間"] = 240;     reminders["5時間"] = 300;   reminders["6時間"] = 360
reminders["7時間"] = 420;     reminders["8時間"] = 480;   reminders["9時間"] = 540
reminders["10時間"] = 600;    reminders["11時間"] = 660;  reminders["0.5日"] = 720
reminders["18時間"] = 1080;   reminders["1日"] = 1440;    reminders["2日"] = 2880
reminders["3日"] = 4320;      reminders["4日"] = 5760;    reminders["1週"] = 10080
reminders["2週"] = 20160

DIM Excel = CREATEOLEOBJ("Excel.Application")
Excel.Visible = TRUE
DIM Workbook = Excel.Workbooks.Open("D:\Desktop\予定一覧.xlsx")

DIM MaxRow = Excel.Cells(Excel.Rows.Count, 1).End(xlUp).Row

DIM Outlook = CREATEOLEOBJ("Outlook.Application")
DIM AppointmentItem = Outlook.CreateItem(olAppointmentItem)

FOR row = 2 TO MaxRow
	PRINT row
	WITH AppointmentItem
		.Subject = Excel.Cells(row, 2).Value        // 件名
		.Location = Excel.Cells(row, 3).Value       // 場所
		.Start = Excel.Cells(row, 4).Value          // 開始時刻
		.End = Excel.Cells(row, 5).Value            // 終了時刻
		IF Excel.Cells(row, 6).Value = "○" THEN .AllDayEvent = TRUE     // 終日
		IFB reminders[Excel.Cells(row, 7).Value] <> -1 THEN
			.ReminderSet = TRUE
			.ReminderMinutesBeforeStart = reminders[Excel.Cells(row, 7).Value]     // リマインダー
		ELSE
			.ReminderSet = FALSE
		ENDIF
		.BusyStatus = 1                             // 公開方法
		.Body = Excel.Cells(row, 8).Value           // 本文
		.Save
	ENDWITH
NEXT

MSGBOX((MaxRow - 1) + "件の予定を登録しました。")

Outlook.Quit
Excel.Quit

HTMLメールを送信(Outlook)

HTMLメールの本文は長くなるので、TEXTBLOCKで定義して代入しています。

UWSC
CONST olMailItem = 0
CONST olFormatHTML = 2

DIM Outlook = CREATEOLEOBJ("Outlook.Application")
DIM MailItem = Outlook.Application.CreateItem(olMailItem)

WITH MailItem
   .BodyFormat = olFormatHTML
   .Subject = "HTMLメールのテスト"
   .HTMLBody = Body
   .To = "contact@example.com"   // 送信先
   Account = Outlook.Session.Accounts.Item("info@example.com")    // 送信元
   .SendUsingAccount = Account
   .Send
ENDWITH

TEXTBLOCK Body
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional/a/EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
   <head>
       <meta name="viewport" content="target-densitydpi=device-dpi,width=device-width,maximum-scale=1.0,user-scalable=yes">
       <meta http-equiv="Content-Language" content="ja">
       <meta charset="shift_jis">
       <title></title>
   </head>
   <body>
       <table border="0" cellpadding="0" cellspacing="0" width="600px">
           <tr>
               <td><img alt="画像" src="http://example.com/image.jpg" width="600px" style="width:600px;"></td>
           </tr>
           <tr>
               <table border="1px" cellpadding="0" cellspacing="0" width="600px">
                   <tr>
                       <td width="50%">テキスト1</td>
                       <td width="50%">テキスト2</td>
                   </tr>
               </table>
           </tr>
       </table>
   </body>
</html>
ENDTEXTBLOCK
使用関数
解説

参考文献

  1. Application.CreateItem メソッド (Outlook) | Microsoft Learn
  2. OlDefaultFolders 列挙型 (Microsoft.Office.Interop.Outlook) | Microsoft Learn

関連記事

Account オブジェクト
Accountオブジェクトは、現在のプロファイルに定義されているアカウントを表します。
Accounts オブジェクト
現在のプロファイルで利用できるアカウントを表すAccountオブジェクトのセットが含まれています。
Application オブジェクト
Outlookアプリケーション全体を表します。
AppointmentItem オブジェクト
新しい予定を表すAppointmentItemオブジェクトを作成します。
Folder オブジェクト
Folders オブジェクト
Items オブジェクト
MailItem オブジェクト
メールメッセージを表します。
NameSpace オブジェクト
Outlookのメールや予定表、連絡先といった様々なデータにアクセスすることができます。
Recipient オブジェクト