vbalearner721
New Member
- Joined
- Apr 27, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hiya, my code is below but it maybe not good, the main problem is the range("B11").CurrentRegion.Select cannot be shown in the email body, what's wrong with my code??? All the other part can be shown correctly except this range ---> data = Range("B11").CurrentRegion.Select
That''s only a word 'True' show for this part, please point out what's wrong, thank you very much.
Sub Draft()
Dim myDataRng As Range
Set myDataRng = Range("c2:c2")
Dim data As String
data = Range("B11").CurrentRegion.Select
For Each Cell In myDataRng
If Cell.Value > 0 Then
Dim objOutlook As Object
Set objOutlook = CreateObject("outlook.application")
Dim objEmail As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
Range("K2").Select
With objEmail
.SentOnBehalfOfName = "accounting@test.co.uk"
.to = ActiveCell.Offset(0, 1).Value
.Subject = ActiveCell.Offset(7, 0).Value
.htmlbody = "Supplier Code " & " " & Cell.Offset(0, 0).Value & "<br>" & _
"Supplier Name: " & " " & Cell.Offset(1, 0).Value & "<br>" & _
"Currency " & " " & Cell.Offset(2, 0).Value & "<br>" & "<br>" & "Dear Supplier," & "<br>" & "<br>" & _
"A payment has been issued to you, as detailed below. " & "<br>" & _
data & "<br>" & "<br>" & _
"Kind Regards, <br>Johnny Grif <br>Accounts Assistant/Accounts Department" & _
"<br>" & "T:+44(0)1234 567 890" & "<br>" & "E:accounting@test.co.uk"
.Save
End With
Set objOutlook = Nothing
End If
Next Cell
Set myDataRng = Nothing
Set objEmail = Nothing: Set objOutlook = Nothing
MsgBox "Please check pyament advice in your draft folder!"
End Sub
The final outcome is like this>>>>>>>>>>>
Dear Supplier,
A payment has been issued to you, as detailed below.
True
....
..
Kind Regards,
Johnny Grif
Accounts Assistant/Accounts Department
T:+44(0)1234 567 890
E:accounting@test.co.uk
That''s only a word 'True' show for this part, please point out what's wrong, thank you very much.
Sub Draft()
Dim myDataRng As Range
Set myDataRng = Range("c2:c2")
Dim data As String
data = Range("B11").CurrentRegion.Select
For Each Cell In myDataRng
If Cell.Value > 0 Then
Dim objOutlook As Object
Set objOutlook = CreateObject("outlook.application")
Dim objEmail As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
Range("K2").Select
With objEmail
.SentOnBehalfOfName = "accounting@test.co.uk"
.to = ActiveCell.Offset(0, 1).Value
.Subject = ActiveCell.Offset(7, 0).Value
.htmlbody = "Supplier Code " & " " & Cell.Offset(0, 0).Value & "<br>" & _
"Supplier Name: " & " " & Cell.Offset(1, 0).Value & "<br>" & _
"Currency " & " " & Cell.Offset(2, 0).Value & "<br>" & "<br>" & "Dear Supplier," & "<br>" & "<br>" & _
"A payment has been issued to you, as detailed below. " & "<br>" & _
data & "<br>" & "<br>" & _
"Kind Regards, <br>Johnny Grif <br>Accounts Assistant/Accounts Department" & _
"<br>" & "T:+44(0)1234 567 890" & "<br>" & "E:accounting@test.co.uk"
.Save
End With
Set objOutlook = Nothing
End If
Next Cell
Set myDataRng = Nothing
Set objEmail = Nothing: Set objOutlook = Nothing
MsgBox "Please check pyament advice in your draft folder!"
End Sub
The final outcome is like this>>>>>>>>>>>
Dear Supplier,
A payment has been issued to you, as detailed below.
True
....
..
Kind Regards,
Johnny Grif
Accounts Assistant/Accounts Department
T:+44(0)1234 567 890
E:accounting@test.co.uk