Ich verwende ein Makro zum Generieren einer Outlook-Vorlage basierend auf Daten, die in eine Arbeitsmappe eingegeben wurden.Ausführen von Makros in der zuletzt hinzugefügten Zeile
In der Arbeitsmappe habe ich 100 Zeilen mit Daten und 7 Blatt.
Ich muss das Makro (auf Knopfdruck) auf die Daten der letzten Zeile ausführen und die Vorlage generieren.
Meine Zeilen enthalten Zeitdaten (Beispiel 13:37, nächste Zeile 14:02 usw.). Ich denke, das könnte ein guter Weg sein, um die letzte Zeile zu identifizieren.
Ich verwende diesen Code. Ich bin die Auswahl der Zeile mit A203: G203
Sub NonConformanceGenerator()
ActiveSheet.Range("A203:G203").Select
Const HEADER_ROW As Long = 202 '<< the row with column headers
Const NUM_COLS As Long = 7 '<< how many columns of data
Const olMailItem = 0
Const olFolderInbox = 6
Dim ol As Object, fldr, ns, msg
Dim html As String, c As Range, colReq As Long, hdr As Range
Dim rw As Range
On Error Resume Next
Set ol = GetObject(, "outlook.application")
On Error GoTo 0
If ol Is Nothing Then
On Error Resume Next
Set ol = CreateObject("outlook.application")
Set ns = ol.GetNamespace("MAPI")
Set fldr = ns.GetDefaultFolder(olFolderInbox)
fldr.display
On Error GoTo 0
End If
If ol Is Nothing Then
MsgBox "Couldn't start Outlook to compose mail!", vbExclamation
Exit Sub
End If
Set msg = ol.CreateItem(olMailItem)
Set rw = Selection.Cells(1).EntireRow
msg.Subject = ""
html = "<style type='text/css'>"
html = html & "body, p {font:11pt calibri;padding:40px;}"
html = html & "table {border-collapse:collapse}"
html = html & "td {border:1px solid #000;padding:8px;}"
html = html & "</style>"
html = html & "<p>Hello,</p>"
html = html & "<table>"
For Each c In rw.Cells(1).Resize(1, NUM_COLS).Cells
If c.Column <> 0 Then '<<< This removes the 4th column if you type number 4 after the <> symbols
Set hdr = rw.Parent.Cells(HEADER_ROW, c.Column) '<< get the header text for this cell
html = html & "<tr><td style='background-color:#FFF;width:200px;'>" & _
hdr.Value & _
"</td><td style='width:400px;'>" & Trim(c.Value) & "</td></tr>"
End If 'we want this cell
Next c
html = html & "</table>"
msg.HTMLBody = html
msg.display
ActiveSheet.Range("A15").Select
End Sub
Sie brauchen nicht einen Bereich, in dem Code wählen - wählen Sie einfach eine beliebige Zelle in der Zeile mit der Maus (oder Tastatur) verwenden und das Makro (vielleicht fügen Sie eine Schaltfläche auf dem Blatt es auszulösen) laufen - Es wird die "aktive" Reihe automatisch aufnehmen. –