メインコンテンツへスキップ

指定した範囲をコピーしてExcelのメール本文に貼り付けてメールを送信するにはどうすればよいですか?

多くの場合、Excelワークシートの指定された範囲のコンテンツは、電子メール通信に役立つ場合があります。 この記事では、指定した範囲でメールを送信する方法をExcelで直接メール本文に紹介します。

指定した範囲をExcelのメール本文に貼り付けてメールを送信する
素晴らしいツールを使用して、指定した範囲をメール本文に貼り付けてメールを送信します

Excelでメールを送信するためのその他のチュートリアル...


指定した範囲をExcelのメール本文に貼り付けてメールを送信する

次のVBAコードは、範囲をコピーして、ExcelのOutlook電子メール本文に直接貼り付けるのに役立ちます。 次のようにしてください。

1.ワークシートにコピーする必要のある範囲が含まれている場合は、を押します。 他の + F11 キーを同時に開いて アプリケーション向け Microsoft Visual Basic 窓。

2.オープニングで アプリケーション向け Microsoft Visual Basic ウィンドウをクリックしてください ツール > 参考文献 以下のスクリーンショットのように。

3。 の中に 参照– VBAProject ダイアログボックスで、を見つけて確認してください MicrosoftOutlookオブジェクトライブラリ オプションをクリックしてから、 OK

4。 クリック インセット > モジュール、次に、以下のVBAコードをコピーしてモジュールウィンドウに貼り付けます。

VBAコード:指定した範囲をExcelのメール本文に貼り付けてメールを送信する

Sub Send_Email()
'Updated by Extendoffice 20200119
    Dim xRg As Range
    Dim I, J As Long
    Dim xAddress As String
    Dim xEmailBody As String
    Dim xMailOut As Outlook.MailItem
    Dim xOutApp As Outlook.Application    
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    For I = 1 To xRg.Rows.Count
        For J = 1 To xRg.Columns.Count
            xEmailBody = xEmailBody & "  " & xRg.Cells(I, J).value
        Next
        xEmailBody = xEmailBody & vbNewLine
    Next
    xEmailBody = "Hi" & vbLf & vbLf & " body of message you want to add" & vbLf & vbLf & xEmailBody & vbNewLine
    With xMailOut
        .Subject = "Test"
        .To = ""
        .Body = xEmailBody
        .Display
        '.Send
    End With
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub

ノート:

  • 1)。 メール本文を一列に変更してください xEmailBody = "Hi"&vbLf&vbLf& "追加したいメッセージの本文"&vbLf&vbLf&xEmailBody&vbNewLine 必要に応じて
  • 2)。 メールの受信者と件名を指定してください(.To = & .Subject = "test") コード内の行。

5。 プレス F5 コードを実行するためのキー。 ポップアップで Kutools for Excel ダイアログボックスで、メール本文に貼り付ける必要のある範囲を選択して、[ OK ボタン。 スクリーンショットを参照してください:

6.これで、指定した受信者、件名、本文、および選択したExcel範囲で電子メールが作成されます。をクリックしてください。 送信 このメールを送信するボタン。 示されているスクリーンショットを参照してください。

Note:VBAコードは、電子メールプログラムとしてOutlookを使用している場合にのみ機能します。


素晴らしいツールを使用して、指定した範囲をメール本文に貼り付けてメールを送信します

Outlookを使用せずに、指定した範囲のデータを貼り付けてExcelで直接メールを送信したい場合は、 メールを送る の有用性 Kutools for Excel あなたのために。 この機能を使用すると、電子メールアドレスの送信サーバーを構成し、将来的にはこの電子メールアドレスを介してExcelで直接電子メールを送信する必要があります。

申請する前に Kutools for Excelについては 最初にダウンロードしてインストールします.

1.まず、必要なフィールドを含むメーリングリストを準備する必要があります。

  • ヒント:メーリングリストには少なくとも2行が含まれ、最初の行はヘッダーである必要があります(ExcelでXNUMXつの電子メールアドレスに電子メールを送信する場合は、次のスクリーンショットのようにヘッダー「Email」を使用してこれらXNUMXつの電子メールアドレスを入力してください)。
  • または、次の方法でメーリングリストを簡単に作成できます。 メーリングリストを作成する 特徴。

2.メール本文にデータを追加する範囲を選択し、 Ctrlキー + C キーを押してコピーします。

3.メーリングリスト全体(ヘッダーを含む)を選択し、をクリックします クツールズプラス > メールを送る。 スクリーンショットを参照してください:

4.次に、 メールを送る ダイアログボックスが表示されます。

  • 4.1)選択したメーリングリストの項目は、対応するフィールドに入力されます(必要に応じてメーリングリストにフィールドを追加できます)。
  • 4.2)メール本文ボックスをクリックし、を押します Ctrlキー + V 選択した範囲データを貼り付けるためのキー。 その後、必要に応じて他のコンテンツを追加します。
  • 4.3チェックを外します Outlook経由でメールを送信する ボックス;
  • 2.4)をクリックします 送信サーバー設定 ボタン。 スクリーンショットを参照してください:

5.次に、 送信サーバー(SMTP)設定–新しいスキーム ダイアログボックスが表示されます。 メールアドレスにサーバー設定を入力し、確認後、送信したメールをすべて保存するフォルダを指定してください。 送信したメールをに保存 ボックスをクリックし、 OK ボタンを押して設定を保存します。

6.に戻ったとき メールを送る ダイアログボックスで 送信 メールを送信するボタン。

今後は、この機能を使用してExcelで直接メールを送信できます。

  このユーティリティの無料トライアル(30日)が必要な場合は、 クリックしてダウンロードしてください、次に、上記の手順に従って操作を適用します。


関連記事:

Excelのセルで指定されたメールアドレスにメールを送信する
電子メールアドレスのリストがあり、Excelで直接これらの電子メールアドレスに電子メールメッセージをまとめて送信するとします。 それを達成する方法は? この記事では、Excelのセルで指定された複数の電子メールアドレスに電子メールを送信する方法を説明します。

Excelで電子メールを送信するときにOutlookの署名を挿入する
Excelで直接電子メールを送信したい場合、どのようにしてデフォルトのOutlook署名を電子メールに追加できますか? この記事では、Excelで電子メールを送信するときにOutlookの署名を追加するのに役立つXNUMXつの方法を提供します。

Excelで複数の添付ファイルを添付してメールを送信する
この記事では、Excelで複数の添付ファイルを添付したOutlookを介した電子メールの送信について説明しています。

Excelで期日が過ぎたらメールを送信する
たとえば、列Cの期日が7日以下の場合(現在の日付は2017/9/13)、列Aの指定された受信者に列Bの指定された内容で電子メールリマインダーを送信します。それを達成しますか? この記事では、それを詳細に処理するためのVBAメソッドを提供します。

Excelのセル値に基づいて自動的にメールを送信する
Excelで指定されたセル値に基づいて、Outlookを介して特定の受信者に電子メールを送信するとします。 たとえば、ワークシートのセルD7の値が200より大きい場合、電子メールが自動的に作成されます。 この記事では、この問題をすばやく解決するためのVBAメソッドを紹介します。

Excelでメールを送信するためのその他のチュートリアル...

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (22)
Rated 4.5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
The only issue is that the format of the table is not maintained in the mail. Can you let me know how do we preserve the format of the table in the mail, I have the same issue, could you see if you could update it please, otherwise this is excellent.
Many thanks
Rated 4.5 out of 5
This comment was minimized by the moderator on the site
Hi Andy Mitchell,
If you want to maintain the format of the table, the following VBA script can do you a favor. Please give it a try. Thank you.
Sub Send_Email()
'Updated by Extendoffice 20220616
    Dim xRg As Range
    Dim I, J As Long
    Dim xAddress As String
    Dim xMailOut As Object
    Dim xOutApp As Object
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    With xMailOut
        .Subject = "Test"
        .To = ""
        .HTMLBody = RangetoHTML(xRg)
        .Display
        '.Send
    End With
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub

 ' The following VBA script is cited from this page:
 ' https://stackoverflow.com/questions/18663127/paste-excel-range-in-outlook
Function RangetoHTML(rng As Range)
' By Ron de Bruin.
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook

    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).Select
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        .DrawingObjects.Delete
        On Error GoTo 0
    End With

    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
         SourceType:=xlSourceRange, _
         Filename:=TempFile, _
         Sheet:=TempWB.Sheets(1).Name, _
         Source:=TempWB.Sheets(1).UsedRange.Address, _
         HtmlType:=xlHtmlStatic)
        .Publish (True)
    End With

    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.ReadAll
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                          "align=left x:publishsource=")

    'Close TempWB
    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function
    Kill TempFile

    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function
This comment was minimized by the moderator on the site
This worked perfectly, thank you so much.
I can now add my spin on it to get it doing what I need.
This comment was minimized by the moderator on the site
Hi Paul Johnson,

Very happy to help you solve the problem. Have a good day at work.
This comment was minimized by the moderator on the site
hello,
can you help me on below
I have create excel sheet & updated 10 supplier mail detailI have send mail through excel to all 10 supplier with individual sheet attachment with individual mail.
I want to paste excel data in outlook body instead of attachment in mail
can any one help me
This comment was minimized by the moderator on the site
Hi,
Instead of selecting the range, I want to select multiple pivots in the excel.
can you please help me.
This comment was minimized by the moderator on the site
Hi,
Instead of selecting the range manually, I want to select the range automatically.
This comment was minimized by the moderator on the site
Hi Raman,
In the below code, please replace the range "A1:C5" in line Set xRg = Range("A1:C5") with your own range.

Sub Send_Email()
Dim xRg As Range
Dim I, J As Long
Dim xAddress As String
Dim xEmailBody As String
Dim xMailOut As Outlook.MailItem
Dim xOutApp As Outlook.Application
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Range("A1:C5")
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xMailOut = xOutApp.CreateItem(olMailItem)
For I = 1 To xRg.Rows.Count
For J = 1 To xRg.Columns.Count
xEmailBody = xEmailBody & " " & xRg.Cells(I, J).Value
Next
xEmailBody = xEmailBody & vbNewLine
Next
xEmailBody = "Hi" & vbLf & vbLf & " body of message you want to add" & vbLf & vbLf & xEmailBody & vbNewLine
With xMailOut
.Subject = "Test"
.To = ""
.Body = xEmailBody
.Display
'.Send
End With
Set xMailOut = Nothing
Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi experts, Do we have updates on how the format maintained?
This comment was minimized by the moderator on the site
Hi Ther,
Can't figure it out. Sorry for that.
This comment was minimized by the moderator on the site
i am seeing a compile error (User-defined type not defined". Please help me out to overcome this.
This comment was minimized by the moderator on the site
Hi,
Please get into the Reference window by clicking Tools > references. Scroll down to find and check the Microsoft Outlook Object Library box and click the OK button to finish the setting.
This comment was minimized by the moderator on the site
this is pasting as a text. Kindly suggest how to send the table or the same format which is copied from the excel.
This comment was minimized by the moderator on the site
Code to send automatically after selecting after ok
This comment was minimized by the moderator on the site
Hi
This code is vary excellent, by using the code i have completed my 90% of my project.
I have same issue as mentioned by Anirudh that is table formatting. How can i format the table in email.
Please help me......
This comment was minimized by the moderator on the site
Good Day,
The problem can't be solved yet. Sorry for the inconvenience and thank you for your comment.
This comment was minimized by the moderator on the site
Hi, Is there any update on below.......
This comment was minimized by the moderator on the site
Hi, Also I Wanted code for "Filter by Date".
I am working on project, on that project I wanted to filter the data by the date, actually we have filter/hide the and last 05 days to current date data and we have highlight all other data.
Please help me to complete this project.
Your help is very great-full for me.
This comment was minimized by the moderator on the site
This is great. It is working as expected. The only issue is that the format of the table is not maintained in the mail. Can you let me know how do we preserve the format of the table in the mail
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations