Answer Question
0
0

Dobrý den. Potřeboval bych donutit Excel, aby poslat oznámení přes MS Outlook na určitou adresu potom, co do určité buňky vyplním určitý text (např. jméno kolegy, kterému pak mail odejde). Našel jsem toto, kde se odešle mail, pokud v dané buňce bude číselná hodnota vyšší než 200, ale potřeboval bych to upravit, aby to reagovalo na ten konkrétní text (např. Novotny). Pomůže někdo? Děkuji.
Dim xRg As Range
‚Update by Extendoffice 2018/3/7
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range(„D7“), Target)
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 200 Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject(„Outlook.Application“)
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = „Hi there“ & vbNewLine & vbNewLine & _
„This is line 1“ & vbNewLine & _
„This is line 2“
On Error Resume Next
With xOutMail
.To = „Email Address“
.CC = „“
.BCC = „“
.Subject = „send by cell value test“
.Body = xMailBody
.Display ‚or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

Marked as spam
Odeslal Jirka
Otázka položena 16.1.2019 12:22
140 views
0
Private answer

No já bych to upravil takto, přičemž tu druhou proceduru jsem vložil do samostatného modulu :

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub

Public Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = "adresa@xxx.cz"
.CC = ""
.BCC = ""
.Subject = "send by cell value test"
.Body = xMailBody
.Display '?or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

Set xRg = Intersect(Range("D7"), Target)
If xRg Is Nothing Then Exit Sub
If Target.Value = "Novotn?" Then
'If IsNumeric(Target.Value) And Target.Value > 200 Then
Call Mail_small_Text_Outlook
End If
End Sub

Marked as spam
Odeslal Anonymous
Odpověděl 24.1.2019 16:33
0
Private answer

Promiňte nějak se to pomíchalo při kopírování, posílám znovu.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("D7"), Target)
If xRg Is Nothing Then Exit Sub
If Target.Value = "Novotn?" Then
'If IsNumeric(Target.Value) And Target.Value > 200 Then
Call Mail_small_Text_Outlook
End If
End Sub

Public Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = "adresa@xxx.cz"
.CC = ""
.BCC = ""
.Subject = "send by cell value test"
.Body = xMailBody
.Display '?or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

Marked as spam
Odeslal Anonymous
Odpověděl 24.1.2019 16:45

Odešlete svou odpověď

Attach YouTube/Vimeo clip putting the URL in brackets: [https://youtu.be/Zkdf3kaso]