Sub MyWdMail() Rem *----*----* *----*----* *----*----* *----*----* Rem Word文書データOutlook電子メール送信処理 Rem 作譜:Hitrock Camellia Shinopy Rem 言語:Word VBA Rem 機能... Rem Wordの文書を電子メールの本文として送信する。 Rem 注記... Rem 1. Microsoft Outlook上で、下記の手作業による事前設定が必要。 Rem Microsoft Outlookのメニューバーの[ツール]から[オプション...]をクリックし、 Rem [メール形式]タブの[電子メールの編集にMicrosoft Wordを使用する]チェックボックスを Rem オンにする。 Rem 2. Microsoft Outlookが起動済みの状態である場合、すぐに電子メールが送信される。 Rem 起動してない場合は、これを起動して[送受信]ボタンを押して送信する必要がある。 Rem 3. 警告なしに送信するので注意すること。 Rem 履歴... Rem 第1版:2006/06/06:作成。 Rem 第2版:2006/06/11:Microsoft Wordでの手作業による事前設定が不要になるよう修正した。 Rem 第3版:2006/06/25:.BodyFormatの設定の不具合を修正した。 Rem 第4版:2006/07/03:文書のコピー・貼り付けをやめ、「.Body = ActiveDocument.Content」に修正した。 Rem 第5版:2008/07/03:Microsoft Outlookのバージョンにより送信する処理方法を分けた。 Rem *----*----* *----*----* *----*----* *----*----* Rem 参照設定する場合... Rem Microsoft Outlook 10.0 Object Library Rem *----*----* *----*----* *----*----* *----*----* Dim myOutlook As Variant ' Outlook.Application Dim myMail As Variant ' MailItem Dim myCmmdBar As CommandBar Dim myCtrl As CommandBarControl Rem *----*----* *----*----* *----*----* *----*----* ' On Error Resume Next Set myOutlook = GetObject(, "Outlook.Application") If Err.Number <> 0 Then Set myOutlook = CreateObject("Outlook.Application") End If On Error GoTo 0 ' Set myMail = myOutlook.CreateItem(0) ' = myOutlook.CreateItem(olMailItem) With myMail .Subject = "このメールはテストです。" .To = "xxxxxxxxx@xxx.com" .BCC = "xxxxxx@xxxx.ne.jp" .FlagRequest = "凄い!" .Importance = 2 ' = olImportanceHigh Rem olImportanceHigh olImportanceLow olImportanceNormal Rem メッセージ形式... Rem テキスト形式の場合、書式設定(文字色・蛍光ペン書式など)は無効になる。 .BodyFormat = 1 ' = olFormatPlain / 2 = olFormatHTML .Body = ActiveDocument.Content .Display End With Rem *----*----* *----*----* *----*----* *----*----* ' If Val(myOutlook.Version) >= 12 Then myMail.Send Else On Error Resume Next Application.CommandBars("Zzz").Delete On Error GoTo 0 ' Set myCmmdBar = Application.CommandBars.Add(Name:="Zzz", Position:=msoBarPopup, Temporary:=True) With myCmmdBar.Controls Set myCtrl = .Add(Type:=msoControlButton, ID:=3708) With myCtrl .Caption = "送信" .DescriptionText = "電子メールの送信コマンドを実行します。" .Execute End With End With myCmmdBar.Delete End If Rem *----*----* *----*----* *----*----* *----*----* ' Set myOutlook = Nothing Set myMail = Nothing Set myCmmdBar = Nothing Set myCtrl = Nothing End Sub ' MyWdMail *----*----* *----*----* *----*----* *----*----*