peter59
Terugkerende gebruiker
- Lid geworden
- 21 mei 2007
- Berichten
- 2.698
- Besturingssysteem
- Windows 11
- Office versie
- Office 365
Hallo,
Ik tracht via een code van Ron de Bruin een werkblad te versturen met in de body een tekst die op een aparte sheet staat.
Onderstaande code gebruik ik.
Het wil maar niet lukken.
Krijg steeds een foutmelding.
Zie bijlage. Hopelijk verschaft deze meer duidelijkheid over dat gene wat ik bedoel.
Dank alvast voor het meedenken.
Mvg
Peter.
Ik tracht via een code van Ron de Bruin een werkblad te versturen met in de body een tekst die op een aparte sheet staat.
Onderstaande code gebruik ik.
Code:
Sub Mail_Every_Worksheet()
'Working in Excel 2000-2013
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim sh As Worksheet
Dim wb As Workbook
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
TempFilePath = Environ$("temp") & "\"
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2013
FileExtStr = ".xlsm": FileFormatNum = 52
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set OutApp = CreateObject("Outlook.Application")
For Each sh In ThisWorkbook.Worksheets
If sh.Range("A1").Value Like "?*@?*.?*" Then
sh.Copy
Set wb = ActiveWorkbook
TempFileName = "Alarmoverzicht " & sh.Name & " van " _
& Format(Now, "dd-mm-yy")
Set OutMail = OutApp.CreateItem(0)
With wb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.to = sh.Range("A1").Value
.CC = ""
.BCC = ""
.Subject = "TEST"
[COLOR="#FFD700"] Body = strbody
Dim cell As Range
Dim strbody As String
For Each cell In ThisWorkbook.Sheets("Tekst Email").Range("A1:A60")
strbody = strbody & cell.Value & vbNewLine_
Next[/COLOR] .Attachments.Add wb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
.Close savechanges:=False
End With
Set OutMail = Nothing
Kill TempFilePath & TempFileName & FileExtStr
End If
Next sh
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Krijg steeds een foutmelding.
Zie bijlage. Hopelijk verschaft deze meer duidelijkheid over dat gene wat ik bedoel.
Dank alvast voor het meedenken.
Mvg
Peter.