Hier ist ein Beispiel, wie Sie erreichen können, was Sie wollen. Bitte ändern Sie es für Ihre tatsächlichen Bedürfnisse.
Ich habe einige Codes von VBA ausprobieren .. Aber ich weiß nicht, wie wirklich die Post funktioniert Funktion sendet? Schicke ich den Anhang raus?
Sie brauchen nicht die gesamte Arbeitsmappe als Anhang zu senden. Sie können eine einfache E-Mail senden, in der Sie angeben, ob der Urlaub genehmigt oder abgelehnt wird. Wenn Sie unterstützen möchten, warum Sie den Urlaub ablehnen oder genehmigen, können Sie die entsprechenden Zellen in die E-Mail einfügen. Siehe dieses Beispiel.
Ich nehme für einen Moment an, dass Ihr Arbeitsblatt so aussieht.

Nehmen wir nun an die Mitarbeiter Siddharth
will einen Urlaub nehmen. Wie wir in der Momentaufnahme sehen können, hat der Mitarbeiter 0
Blattsaldo. So ist der Antrag auf Zulassung wird abgelehnt und eine Mail an die betreffende Person erschossen/Dept
Wenn Sie den Code ausführen, werden Sie gefragt, die Mitarbeiter

Namen eingeben und dann sendet die entsprechende E-Mail.

CODE
Option Explicit
'~~> To Field in Email
Const strTo As String = "[email protected]"
'~~> CC field in email. If you do not want to CC then change "[email protected]" to ""
Const strCC As String = "[email protected]"
'~~> This is what goes in the body
Const strBody1 As String = "Dear XYZ,"
Const strBody2 As String = "This is in reference to leave request for employee "
Const strBodyApp As String = "The employee has sufficient leave balance and can take the leave"
Const strBodyNotApp As String = "The employee doesn't have sufficient leave balance and hence cannot take the leave"
Const strByeBye As String = "Thanks and Regards"
Const sender As String = "ABC"
Sub Sample()
Dim ws As Worksheet
Dim aCell As Range
Dim Ret
Dim Bal As Long
Dim Rw As Long
Ret = Application.InputBox("Please enter the name of the employee who wants to take a leave")
If Ret = "" Then Exit Sub
Set ws = Sheets("Sheet3")
Set aCell = ws.Columns(2).Find(What:=Ret, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
Bal = aCell.Offset(, 5).Value
Rw = aCell.Row
If Bal > 0 Then
Approved Ret, True, Rw
Else
Approved Ret, False, Rw
End If
Else
MsgBox "The employee " & Ret & " was not found"
End If
End Sub
Sub Approved(EmpName, app As Boolean, lRow As Long)
Dim msg As String
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
If app = True Then
msg = "<p class=MsoNormal>" & strBody1 & "<o:p></o:p></p>" & vbNewLine & _
"<p class=MsoNormal><o:p> </o:p></p>" & vbNewLine & _
"<p class=MsoNormal>" & strBody2 & EmpName & ". " & strBodyApp & _
"<span style='mso-fareast-font-family:""Times New Roman""'><o:p></o:p></span></p>"
Else
msg = "<p class=MsoNormal>" & strBody1 & "<o:p></o:p></p>" & vbNewLine & _
"<p class=MsoNormal><o:p> </o:p></p>" & vbNewLine & _
"<p class=MsoNormal>" & strBody2 & EmpName & ". " & strBodyNotApp & _
"<span style='mso-fareast-font-family:""Times New Roman""'><o:p></o:p></span></p>"
End If
Set rng = Sheets("Sheet3").Range("A1:F1" & ",A" & lRow & ":F" & lRow)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = strTo
.CC = strCC
.BCC = ""
.Subject = "Leave Status"
.HTMLBody = msg & _
RangetoHTML(rng) & _
"<p class=MsoNormal><span style='mso-fareast-font-family:""Times New Roman""'>" & strByeBye & "<o:p></o:p></span></p>" & _
"<p class=MsoNormal><span style='mso-fareast-font-family:""Times New Roman""'><o:p> </o:p></span></p>" & _
"<p class=MsoNormal><span style='mso-fareast-font-family:""Times New Roman""'>" & sender & "<o:p></o:p></span></p>"
.Display '.Send 'To send the email
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
'~~> Taken from http://www.rondebruin.nl/mail/folder3/mail4.htm
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2010
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
With TempWB.PublishObjects.Add(_
SourceType:=xlSourceRange, _
fileName:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
'Close TempWB
TempWB.Close savechanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
HAFTUNGSAUSSCHLUSS: Da der obige Code ein einfaches Beispiel ist, habe ich nicht
1) inklusive Fehlerbehandlung (die Sie sollten)
2) verwendete grundlegende Sachen wie Application.ScreenUpdating
Beispieldatei: Dieser Link ist für die nächsten 7 Tage aktiv.Ich habe eine Beispieldatei hochgeladen für Sie :)
http://wikisend.com/download/562482/Sample.xls
HTH
Ron es in seinem Blog bedeckt zu spielen hat. http://www.rondebruin.nl/sendmail.htm, Schau es dir an. –
Gibt es eine Möglichkeit, dies in etwas anderes als Excel zu tun? Programmieren von MS Office ist eigentlich sehr schmerzhaft, weil Dinge oft nicht ganz so funktionieren wie dokumentiert. Wenn Sie damit fertig sind, wünsche ich Ihnen viel Glück und empfehle Ihnen, Ihre Freizeit damit zu verbringen, ein anderes Programm zu erlernen. – Marcin
@Marcin: Mit Respekt, ich stimme dir nicht zu :) –