我是VBA的新手,已经从同事模板中设置了大部分代码,并在此处进行了一些调整。
我坚持要添加电子邮件签名,希望有人可以提供帮助。 另外,我想格式化电子邮件中的值为£#,## 0; [Red]£(#,## 0)
我甚至不知道如何添加下面的代码作为收到错误消息,指出它没有正确格式化为代码?!
有人可以帮忙吗?
'Open Email for Attachments
Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)
'set sheet to find address for e-mails as I have several people to mail to
Set rngeAddresses = Sheets("New").Range("AB4")
For Each rngeCell In rngeAddresses.Cells
strRecipients = strRecipients & ";" & rngeCell.Value
Next
'Set CC
aEmail.CC = Sheets("New").Range("AC4")
'set Importance
aEmail.Importance = 1
'Set Subject
aEmail.Subject = "MW Payment Certificate" & " - " & Range("H7") & " - " & Range("H6")
'Set Body for mail
'CAN USE EITHER HTMLBODY OR BODY (BODY IS EASIER)
'aEmail.body = "Hello" & Chr(10) & Chr(10) & "Please find attached the Payment Certificate for valuation no." & Chr(9) & Range("Y9") & Chr(10) & Chr(10) & "Requesting payment to:" & Chr(10) & Chr(10) & "Contractor Name: " & Range("H7") & Chr(10) & "Description of Works: " & Range("H5") & Chr(10) & "Region: " & Range("H6") & Chr(10) & "PO Number: " & Range("H9") & Chr(10) & Chr(10) & "For the amount of: £ " & Range("Y19") & Chr(10) & "Payment due date: " & Range("H20") & Chr(10)
'aEmail.Body = "Hello," & Chr(10) & Chr(10) & "Please find attached the Payment Certificate Number" & Range("Y8")"
aEmail.HTMLBody = "<p style='font-family:calibri;font-size:14.5'>" & "Hello" & "<br><br>" & "Please find attached the Payment Certificate for valuation no. " & Range("Y9") & "<br>" & "Kindly accrue for the below completed works: " & "<br><br>" & "<b>Contractor Name : </b>" & Range("H7") & "<br>" & "<b>Description of Works: </b>" & Range("H5") & "<br>" & "<b>Location of works: </b>" & Range("H6") & "<br>" & "<b>PO Number: </b>" & Range("H9") & "<br><br>" & "<b>For the amount of: </b>" & Range("Y19") & "<br>" & "<b>Approx. payment due date: </b>" & Range("H20") & "<br><br><br>" & "<b><i>Accounts payable</b></i>" & " this is for information purposes only." & "<br>" & "An authorised hard copy will follow shortly." & "<br><br><br>" & "Kind Regards" _
'& "<br>" & "<b>Keysafe Code: </b>" & Range("B34") & "<br>" & "<b> Property Cleared: </b>" & Range("B35") & "<br>" & "<b>Decant Required: </b>" _
'& Range("B36") & "<br>" & "<b>Tenant Name and Number: </b>" & Range("B39") & " - " & Range("B40") & "<br>" & "<b>Visiting Rules: </b>" & Range("B41") & "<br><br>" & "<b><i>Manager Review & Approval</b></i>" & "<br>" & "<b>Manager Name: </b>" & Range("B48") & "<br>" & "<b>Manager Approved: </b>" & Range("B49") & "</p>"
'aEmail.Body = "Hi," & Chr(10) & Chr(10) & "Please see below details of a request for the following recommendations and attached the supporting documentation:" & Chr(10) & Range("S8") & Chr(10) & "Description of Works: " & Range("B42") & Chr(10) & "Any Urgent Work due to H&S concerns: " & Range("B43") & Chr(10) & Chr(10) & "About Requester" & Chr(10) & "Organisation Section: " & Range("B22") & Chr(10) & "Team: " & Range("B23") & Chr(10) & "Contract Area: " & Range("B25") & Chr(10) & Chr(10) & "Property Information" & Chr(10) & "URPN: " & Range("B28") & Chr(10) & "Block Code (if applicable): " & Range("B29") & Chr(10) & "Address: " & Range("B30") & Chr(10) & "Post Code: " & Range("B31") & Chr(10) & "Void: " & Range("B33") & Chr(10) & "Decant Required: " _
'& Range("B34") & Chr(10) & "Tenant Name and Number: " & Range("B37") & " - " & Range("B38") & Chr(10) & "Visiting Rules: " & Range("B39") & Chr(10) & Chr(10) & "Manager Review & Approval" & Chr(10) & "Manager Name: " & Range("B46") & Chr(10) & "Manager Approved"
'Set Signature
'aEmail.Signature = Email.body
'Set attachment
aEmail.ATTACHMENTS.Add ActiveWorkbook.FullName
'Set Recipient
aEmail.To = strRecipients
'or send one off to 1 person use this static code
'aEmail.Recipients.Add "E-mail.address-here@ntlworld.com"
'Send Mail/display
aEmail.Display
'Clear Form for Next Request
'Select Sheet
'Sheets("NEW").Select
'Range("A23").Select
'**Application.CutCopyMode = True**
'Save This Workbook
Workbooks("Payment Certificate Template.xlsm").Save