从Excel VBA创建新电子邮件 [英] New email create from Excel VBA

查看:103
本文介绍了从Excel VBA创建新电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel中有电子邮件注册.我需要创建命令按钮以打开包含最后一行详细信息的新电子邮件.即最后一行,C列,F列.请注意,以前发送的电子邮件有数百行.如何为该命令按钮编写代码.

I have email register in Excel. I need to create Command Button to open new email with last row details. i.e. last row, column C , column F . Please note there are hundreds of rows are existing with previously sent emails. How to write codes for that Command Button.

预先感谢

污水

推荐答案

*适用于以下

Private Sub CommandButton22_Click()
    Dim a As Integer
    Dim objOutlook As Object
    Dim objMail As Object
    Dim rngTo As Range
    Dim rngSubject As Range
    Dim rngBody As Range
    Dim rngAttach As Range

    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)

    a = ActiveCell.Row

    With ActiveSheet
        Set rngTo = .Cells(a, "C")
        Set rngSubject = .Cells(a, "E")
        'Set rngBody = .Range("B3")
        'Set rngAttach = .Range("B4")
    End With

    With objMail
        .To = rngTo.Value
        .Subject = rngSubject.Value
        '.Body = rngBody.Value
       '.Attachments.Add rngAttach.Value
        .Display 'Instead of .Display, you can use .Send to send the email _
                    or .Save to save a copy in the drafts folder
    End With

    Set objOutlook = Nothing
    Set objMail = Nothing
    Set rngTo = Nothing
    Set rngSubject = Nothing
    Set rngBody = Nothing
    Set rngAttach = Nothing
End Sub

关于,w

这篇关于从Excel VBA创建新电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆