09.11.2019, 17:24
Hallo,
teste mal
Kopier aber bitte das zweite Makro auch mit.
teste mal
Code:
Private Sub prcPira_Click()
'Materialanforderung per email
Const olMailItem As Long = 0
Dim objOutlook As Object
Dim objEmail As Object
Dim wkbVersand As Workbook
Dim strName As String
Dim iCounter, xCounter As Long
Set wkb1 = ThisWorkbook
Set wkb2 = Workbooks.Add(1)
Set wks2 = wkb2.Sheets(1)
wkb1.Activate
With ThisWorkbook.Sheets(1).Cells(13, 54)
If .Value = Date Then
.Offset(, 1) = .Offset(, 1) + 1
Else
.Value = Date
.Offset(, 1) = 1
End If
End With
For iCounter = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(iCounter) And xOpt = 1 Or xOpt = 2 Then
Set XBlatt = Sheets(ListBox1.List(iCounter, 0))
XZeile = Range(ListBox1.List(iCounter, 1)).Row
XBlatt.Cells(XZeile, 54).Value = Date
xCounter = xCounter + 1
XBlatt.Range("D" & XZeile & ",F" & XZeile & ",H" & XZeile & ",K" & XZeile & ",N" & XZeile & ",R" & XZeile & ",S" & XZeile & ",T" & XZeile & ",AR" & XZeile & ",AS" & XZeile & ",AT" & XZeile & ",AU" & XZeile & ",AV" & XZeile & ",AY" & XZeile & "").Copy wks2.Cells(xCounter, 1)
'andere Spalte nehmen!
XBlatt.Cells(XZeile, 55).Value = ThisWorkbook.Sheets(1).Cells(13, 55).Value
End If
Next iCounter
wks2.Copy
'ActiveWorkbook.SaveAs "C:\" & XBlatt.Name, 51
wkb2.SaveAs ThisWorkbook.Path & "C:\" & XBlatt.Name, 51
Set wkbVersand = wkb2
strName = wkbVersand.FullName
wkbVersand.Close
On Error GoTo ErrHandler
' SET Outlook APPLICATION OBJECT.
Set objOutlook = CreateObject("Outlook.Application")
' CREATE EMAIL OBJECT.
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = "alexander.kokscharow@durr.com"
.Subject = "Material Request from Site Manager"
.Body = "Dear Site Logistics Manager," & vbCrLf & vbCrLf & _
"Please find attached the material request, with like to ask you to prepper for me soon." & vbCrLf & "As soon as Material ready to pick up please contact me." & vbCrLf & "Many Thank "
' .Display
' .Attachments.Add ("C:\neue erzeugte excel.xls")
.Attachments.Add strName
.Send
End With
Kill strName
' CLEAR.
Set objEmail = Nothing: Set objOutlook = Nothing
Application.OnTime Now + TimeValue, "prcSchliessen"
ErrHandler:
End Sub
Sub prcSchliessen()
Application.DisplayAlerts False
Application.Quit
End Sub
Kopier aber bitte das zweite Makro auch mit.
Gruß Stefan
Win 10 / Office 2016
Win 10 / Office 2016