MasterBash
New Member
- Joined
- Jan 22, 2022
- Messages
- 47
- Office Version
- 365
- 2021
- Platform
- Windows
Hello,
Adding an image and the code
Inside of module :
Inside of the worksheet :
When I click Send e-mail, I would like to send the data from G2 to K5, but I get an error everytime I try to add the entire range inside of body = Range("G2")
The best case scenario, it would not add to the e-mail column K, because all the values are at 0. However, if K would have values > 0, then add that column to the e-mail (This should actually apply to all columns H and K, not just K).
How can I do that ?
Thank you !
Adding an image and the code
Inside of module :
VBA Code:
Sub AddHyperlink()
Dim rng As Range, cel As Range
With Sheets("Sheet1")
Set rng = .Range("G1")
For Each cel In rng
.Hyperlinks.Add anchor:=cel, Address:="", SubAddress:=cel.Address(0, 0), TextToDisplay:=cel.Text
Next cel
End With
End Sub
Inside of the worksheet :
VBA Code:
Option Explicit
Dim subject As String
Dim body As String
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Range(Target.SubAddress).Column = 7 Then
subject = Date
body = Range("G2")
Call Send_The_Emails
End If
End Sub
Sub Send_The_Emails()
Dim OApp As Object, OMail As Object, signature As String
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
With OMail
.Display
End With
signature = OMail.body
With OMail
.To = Range("P1").Value
.subject = "Here is the report for " & subject
.body = "Hello, " & vbNewLine & vbNewLine & _
"" & body & "" _
& vbNewLine & vbNewLine & signature
.Display
'.Send
End With
Set OMail = Nothing
Set OApp = Nothing
End Sub
When I click Send e-mail, I would like to send the data from G2 to K5, but I get an error everytime I try to add the entire range inside of body = Range("G2")
The best case scenario, it would not add to the e-mail column K, because all the values are at 0. However, if K would have values > 0, then add that column to the e-mail (This should actually apply to all columns H and K, not just K).
How can I do that ?
Thank you !