【问题标题】:Hi, I want to make a button to send or display the message with conditions. VBA嗨,我想制作一个按钮来发送或显示带有条件的消息。 VBA
【发布时间】:2022-08-16 23:27:31
【问题描述】:

我不是专家,我正在尽力而为,但我想创建一个按钮来发送/显示电子邮件,具体取决于另一个单元格中是否有值。如果有这个值,发送。

Sub sendCustEmails()
    
    Dim objOutlook As Object
    Set objOutlook = CreateObject(\"Outlook.Application\")
    Dim objEmail As Object
    Set objEmail = objOutlook.CreateItem(oMailItem)
    Dim strMailBody As String
    
    intRow = 2
    strISO = ThisWorkbook.Sheets(\"MS_Data\").Range(\"B\" & intRow).Text
    
    While (strISO <> \"\")
    
    Set objEmail = objOutlook.CreateItem(oMailItem)
    
    StrMailSubject = ThisWorkbook.Sheets(\"Mail_Details\").Range(\"A2\").Text
     strMailBody = \"<BODY style=\'font-size:11pt;font-family:Calibri(Body)\'>\" & ThisWorkbook.Sheets(\"Mail_Details\").Range(\"B2\").Text & \"</BODY>\"
    strMailBody = Replace(strMailBody, Chr(10), \"<br>\")
    
    strFolder = \"C:\\Users\\CIOTTIC\\OneDrive - IAEA\\Desktop\\AL TEST\"
    strISO = ThisWorkbook.Sheets(\"MS_Data\").Range(\"B\" & intRow).Text
    strSalutation = ThisWorkbook.Sheets(\"MS_Data\").Range(\"C\" & intRow).Text
    strEmail = ThisWorkbook.Sheets(\"MS_Data\").Range(\"D\" & intRow).Text
    strCC = ThisWorkbook.Sheets(\"MS_Data\").Range(\"E\" & intRow).Text
    strFile = ThisWorkbook.Sheets(\"MS_Data\").Range(\"F\" & intRow).Text
    strFile2 = ThisWorkbook.Sheets(\"MS_Data\").Range(\"G\" & intRow).Text
    
    StrMailSubject = Replace(StrMailSubject, \"<ISO>\", strISO)
    strMailBody = Replace(strMailBody, \"<Salutation>\", strSalutation)

    With objEmail
       .To = CStr(strEmail)
       .CC = CStr(strCC)
       .Subject = StrMailSubject
       .BodyFormat = olFormatHTML
       .Display
       .Attachments.Add strFolder & \"\\\" & strFile
       .Attachments.Add strFolder & \"\\\" & strFile2
       .HTMLBody = strMailBody & .HTMLBody
       .Send
       
    End With
    
         intRow = intRow + 1
         strISO = ThisWorkbook.Sheets(\"MS_Data\").Range(\"B\" & intRow).Text
   Wend
   MsgBox \"Done\"
   
End Sub

我需要像这个人那样做https://www.youtube.com/watch?v=q9kTgTghN2g(显示/发送/运行)

非常感谢!

  • 问题是什么?

标签: excel vba


【解决方案1】:

怎么样 :

Sub Test()

If Range("A1").Value <> "" Then
    GoTo SendEmail
    Else: Exit Sub
End If
Send Email:
'Enter the rest of your code here.
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多