• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

2 of meerdere tabbladen versturen via e-mail.

Status
Niet open voor verdere reacties.
Beste HSV ;)

Heb geprobeerd een mail naar u toe te sturen, maar ik kan geen bijlagen mee versturen.

Heb een berichtje naar Ron De Bruin gestuurd en heb het volgende terug gekregen.

Hij zoekt naar "Dagprognose" en die sheet bestaat niet in het nieuwe bestand

Normaal zet hij automatisch de verwijzing naar het orginele bestand in de formula
maar omdat je Indirect gebruikt werkt dat niet.

Je enige mogelijkheid is na dat je array copy doet alle cellen er overheen te plakken als waarden

De code die ik nu gebruik van Ron is deze:

Code:
Sub Mail_Sheets_Array()
'Working in 97-2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim sh As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window
    Dim I As Long

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    'Copy the sheets to a new workbook
    'We add a temporary Window to avoid the Copy problem
    'if there is a List or Table in one of the sheets and
    'if the sheets are grouped
    With Sourcewb
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        .Sheets(Array("Tussen-Eindklassement", "Prijzenverdeling")).Copy
    End With

    'Close temporary Window
    TempWindow.Close

    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2010, we exit the sub when your answer is
            'NO in the security dialog that you only see  when you copy
            'an sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    '    'Change all cells in the worksheets to values if you want
        For Each sh In Destwb.Worksheets
            sh.Select
            With sh.UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
            Destwb.Worksheets(1).Select
        Next sh

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Overzicht " & Format(Now, "dd-mmm-yy")

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
        For I = 1 To 3
            .SendMail "deschepper.danny@telenet.be", _
                      "Overzicht TOUR de FRANCE " & Format(Now, "yyyy")
            If Err.Number = 0 Then Exit For
        Next I
        On Error GoTo 0
        .Close SaveChanges:=False
    End With

    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub

Zou je eventueel een code kunnen tussen schrijven die de cellen overlappen met waardes voordat het bestandje wordt verstuurd.

Graag zou ik ook willen dat de tabbladen dynamisch worden ingegeven (Groen gekleurd in de code) die in kolom C staan op tabblad E-mailadressen.
Dat de geselecteerde tabbladen worden verzonden naar alle spelers die in kolom A staan.

Waarschijnlijk kan dit met de volgende code:

Dim MyArr As Variant
MyArr = ThisWorkbook.Sheets("E-mailadressen").Range("A1:A100")
.SendMail MyArr, "Overzicht TOUR de FRANCE " & Format(Now, "yyyy")

Zie bijgevoegd bestandje bij tabblad E-mailadressen.
Als test mag je het bestandje altijd naar mij sturen.

Zie dit bestandje

Heb deze al persoonlijk naar Daniël en Wim gestuurd.

Groetjes Danny. :thumb:
 
Hallo Danny,

Ik zal er morgen eens naar kijken, en bestuderen.
Ik kan je helaas niks beloven, daar mijn kennis te gering is.

Ps: Naar Daniël wist ik al.
Zo nu en dan mailen we elkaar eens over koetjes en kalfjes, en helpen elkaar waar nodig met Excel.
Achter de schermen dus. :D
 
Danny en Harry , als amateur heb ik deze in elkaar :p
Code:
Sub Mail_Sheets_Array()
'Working in 97-2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim sh As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window
    Dim I As Long

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
  
    [COLOR="black"][COLOR="red"]Sheets(Array("Tussen-Eindklassement", "Prijzenverdeling")).Copy Before:=Sheets(1) ' dit stukje is derbij gezet
    
    Sheets("Prijzenverdeling (2)").Select
    Cells.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    Sheets("Tussen-Eindklassement (2)").Select
    Cells.Copy
    Selection.PasteSpecial Paste:=xlPasteValues[/COLOR][/COLOR]
    
   
   On Error Resume Next
    Set Sourcewb = ActiveWorkbook

    'Copy the sheets to a new workbook
    'We add a temporary Window to avoid the Copy problem
    'if there is a List or Table in one of the sheets and
    'if the sheets are grouped
   
    With Sourcewb
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        .Sheets(Array("Tussen-Eindklassement (2)", "Prijzenverdeling (2)")).Copy
    End With

    'Close temporary Window
    TempWindow.Close

    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2010, we exit the sub when your answer is
            'NO in the security dialog that you only see  when you copy
            'an sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    '    'Change all cells in the worksheets to values if you want
        For Each sh In Destwb.Worksheets
            sh.Select
            With sh.UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
            Destwb.Worksheets(1).Select
        Next sh

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Overzicht TOUR de FRANCE " & Format(Now, "dd-mmm-yy")

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
        For I = 1 To 3
            .SendMail "deschepper.danny@telenet.be", _
                      "Overzicht TOUR de FRANCE " & Format(Now, "yyyy")
            If Err.Number = 0 Then Exit For
        Next I
        On Error GoTo 0
        .Close SaveChanges:=False
    End With

    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr
    
   [COLOR="red"]Sheets(Array("Tussen-Eindklassement (2)", "Prijzenverdeling (2)")).Delete  ' deze is derbij gezet[/COLOR]
   
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub

De tekst van RON
Je enige mogelijkheid is na dat je array copy doet alle cellen er overheen te plakken als waarden
en array kopie gedaan en de cellen erover geplakt als waarde en dan op het einde v/d rit een array delete
 
Laatst bewerkt:
dit heb ik ervan gemaakt
Code:
Option Explicit

'Const MyPath   As String = "C:\Users\asus\Documents\Werk\"
Const MyPath   As String = "C:\data\excell\forum"

Sub AanmaakBijlage()
  Dim NewBook As Workbook, Bereik As Range

  Application.SheetsInNewWorkbook = 2                      'aantal werkbladen in nieuwe map
  Set NewBook = Workbooks.Add                              'maak nieuwe map

  Set Bereik = ThisWorkbook.Sheets("Tussen-Eindklassement").Range("A1:T103")  '1e te kopieren bereik
  Bereik.Copy
  With NewBook.Sheets(1)
    .Name = "Tussen-Eindklassement"                        'benoem 1e sheet
    .Range("a1").PasteSpecial xlAll                        'plak alles
    .Range("a1").PasteSpecial xlPasteColumnWidths          'kolombreedtes gelijk maken
    .Range("A1").Resize(Bereik.Rows.Count, Bereik.Columns.Count).Value = Bereik.Value  'waarden erin zetten
    With Application                                       'dit is enkel om selectie ongedaan te maken
      .CutCopyMode = False
      .Goto .Range("A1"), True
    End With
  End With

  Set Bereik = ThisWorkbook.Sheets("Prijzenverdeling").Range("A1:D39")
  Bereik.Copy
  With NewBook.Sheets(2)
    .Name = "Prijzenverdeling"
    .Range("a1").PasteSpecial xlAll
    .Range("a1").PasteSpecial xlPasteColumnWidths
    .Range("A1").Resize(Bereik.Rows.Count, Bereik.Columns.Count).Value = Bereik.Value
    With Application
      .CutCopyMode = False
      .Goto .Range("A1"), True
    End With
  End With
  Application.CutCopyMode = False

  On Error Resume Next
  NewBook.SaveAs MyPath & IIf(Right(MyPath, 1) <> "\", "\", "") & "MijnBijlage" & ".xls", FileFormat:=56
  If Err.Number <> 0 Then
    MsgBox "het bestand is niet netjes opgeslagen, bestaat die map ?"
  Else
    NewBook.Close
  End If

End Sub
 
En waarom mag ik niet meespelen :cool: Ik voel mij hier wel een beetje buitengesloten, zenne :(
Danny, maak voor de lijst met mailadressen een dynamisch bereik met de naam Maillist, deze wordt dan in de macro gebruikt om naar alle adressen tegelijkertijd te zenden.
Code:
Sub Mail_Sheets_Array()
'Working in 97-2010
    Dim FileExtStr As String, FileFormatNum As Long
    Dim Sourcewb As Workbook, Destwb As Workbook
    Dim TempFilePath As String, TempFileName As String
    Dim sh As Worksheet, I As Long
    Dim TheActiveWindow As Window, TempWindow As Window
    Dim rng As Range, Arr() As String, N As Integer, cell As Range
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    Set Sourcewb = ActiveWorkbook
    [COLOR="red"]Set rng = Sourcewb.Sheets("E-mailadressen").Range("Maillist")
    ReDim Preserve Arr(1 To rng.Cells.Count)
    N = 0
    For Each cell In rng
        If cell.Value Like "?*@?*.?*" Then
            N = N + 1
            Arr(N) = cell.Value
        End If
    Next cell
    ReDim Preserve Arr(1 To N)[/COLOR]
    With Sourcewb
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        .Sheets(Array("Tussen-Eindklassement", "Prijzenverdeling")).Copy
    End With
    TempWindow.Close
    Set Destwb = ActiveWorkbook
    With Destwb
        If Val(Application.Version) < 12 Then
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
           If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With
    For Each sh In Destwb.Worksheets
            sh.Select
            With sh.UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
            Destwb.Worksheets(1).Select
        Next sh
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Overzicht TOUR de FRANCE " & Format(Now, "dd-mmm-yy")
    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
        For I = 1 To 3
            [COLOR="red"].SendMail Array(Arr), _
            "Overzicht TOUR de FRANCE " & Format(Now, "yyyy")
            [/COLOR]If Err.Number = 0 Then Exit For
        Next I
        On Error GoTo 0
        .Close SaveChanges:=False
    End With
    Kill TempFilePath & TempFileName & FileExtStr
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 
nu je het toch over emailadressen hebt, daar zitten vaak tikfouten of zo in, dan is vooraf testen al eens aan te raden, dus WarmBakkertje je test " If cell.Value Like "?*@?*.?*" Then " zou je ook kunnen vervangen door een aanroep naar Geldigemailadres
Code:
Option Explicit

'********************************************************************************************************
'meer uitleg over geldige emailadressen in te vinden op http://www.regular-expressions.info/email.html  '
'met dank aan Alphamax voor de doorverwijzing                                                         '
'voor 99% van de gevallen is Patroon1 voldoende, maar de uitzonderingen bevestigen de regel             '
'voor 99,99% van de gevallen is er Practical1RFC2822                                                    '
'********************************************************************************************************

Public Const Opsomming = "|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum"  'komen er later nog nieuwe extensies bij, voeg die dan hier toe
Public Const Patroon1 = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"  '99% van de emailadressen gecheckt, 2 a 4 letters na het "." in het gedeelte na @
Public Const Patroon2 = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$"  'adressen met "*.museum ook gecheckt, maar anderen dan weer toegelaten die mogelijks niet goed zijn
Public Const Patroon3 = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}opsomming)$"  'check voor 2 letters na het ".", dus landcodes en die andere extensies van opsomming
Public Const OfficialRFC2822 = "^(?:[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*"")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$"
Public Const Practical1RFC2822 = "^[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?\.)+[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?$"
Public Const Practical2RFC2822 = "^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}opsomming)$"

Function GeldigEmailadres(mailadres As String, Optional Patroon = Practical1RFC2822) As Boolean
  With CreateObject("VBScript.RegExp")
    If IsNumeric(Patroon) Then
      .Pattern = Replace(Choose(Patroon, Patroon1, Patroon2, Patroon3, Practical2RFC2822, OfficialRFC2822, Practical1RFC2822), "opsomming", Opsomming)
    Else
      .Pattern = Patroon
    End If
    GeldigEmailadres = .test(UCase(mailadres))
  End With
End Function

Sub TestEenEmailadres()
  Dim bGeldig  As Boolean
  bGeldig = GeldigEmailadres("mijn1eeimailadres@iets.elders")
  If bGeldig = False Then MsgBox "dat is een fout emailadres"
End Sub
 
Nu de VBAers er zijn gaat dit draadje voor Danny wel opgelost worden .
@ Rudi we hoopten al dat je wilde meespelen en Bart ik had al een mail aan Danny gestuurd om het eventueel nits toelating vzn de moderator om het op " worksheet.nl " te zetten om zou jous aandacht te trekken . Rudi en Bart van mijnentwege :thumb: :thumb:
 
Beste warme bakkertje ;)

En waarom mag ik niet meespelen :cool: Ik voel mij hier wel een beetje buitengesloten, zenne :(

Voor dat ik alles gaat nakijken even dit voor warme bakkertje.
Ik ben u niet vergeten hoor :d :p
Zie mijn post #18.

Groetjes Danny. :thumb:
 
Beste Helpers (zo vergeet ik niemand :d)

@ Cow 18 ;)
Deze code is goed wat betreft opmaak en waardes, enkel moet ik ze zelf nog verzenden.

@ warme bakkertje ;)
De tabbladen worden verzonden, maar de waarden zijn #VERW! als resultaat de opmaak is goed.

@ Trucker10 ;)
Bij u krijg ik een foutmelding bij de volgende regel:

"Selection.Past.Special Paste:=xlPasteValues"

@ HSV, Ginger en Wigi ;)
Ik blijf nog even afwachten op jullie resultaat.

Zoals ik het nu overlopen hebt is het een mix van Cow18 (zijn waardes en opmaak) en warme bakkertje (zijn verzenden met de maillist)

Bedankt hiervoor en voor sommige hun nachtrust :d

Groetjes Danny. :thumb:
 
Laatst bewerkt:
Beste Helpers ;)

Heb een mix gedaan van het bestandje Trucker10, dat hij mij heeft toegestuurd en dat van warme bakkertje.
Deze code werkt perfect, alleen wil ik graag de tabbladen dynamisch maken die in tabblad “E-mailadressen” staan in kolom C. (te verzenden tabbladen)
Hoe kan ik ook een .Body aan de e-mail aan toevoegen ?

Zie de code:

Code:
Sub Mail_Sheets_Array4_Trucker10()
'Working in 97-2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim sh As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window
    Dim I As Long
    Dim rng As Range, Arr() As String, N As Integer, cell As Range
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    Set Sourcewb = ActiveWorkbook
    Set rng = Sourcewb.Sheets("E-mailadressen").Range("Maillist")
    ReDim Preserve Arr(1 To rng.Cells.Count)
    N = 0
    For Each cell In rng
        If cell.Value Like "?*@?*.?*" Then
            N = N + 1
            Arr(N) = cell.Value
        End If
    Next cell
    ReDim Preserve Arr(1 To N)
    End With
  
    Sheets(Array("Tussen-Eindklassement", "Prijzenverdeling")).Copy Before:=Sheets(1) ' dit stukje is derbij gezet
    Sheets("Prijzenverdeling (2)").Select
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    
    Sheets("Tussen-Eindklassement (2)").Select
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    
   
   On Error Resume Next
    Set Sourcewb = ActiveWorkbook

    'Copy the sheets to a new workbook
    'We add a temporary Window to avoid the Copy problem
    'if there is a List or Table in one of the sheets and
    'if the sheets are grouped
   
    With Sourcewb
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        .Sheets(Array("Tussen-Eindklassement (2)", "Prijzenverdeling (2)")).Copy
    End With

    'Close temporary Window
    TempWindow.Close

    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2010, we exit the sub when your answer is
            'NO in the security dialog that you only see  when you copy
            'an sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    '    'Change all cells in the worksheets to values if you want
        For Each sh In Destwb.Worksheets
            sh.Select
            With sh.UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
            Destwb.Worksheets(1).Select
        Next sh

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Overzicht TOUR de FRANCE " & Format(Now, "dd-mmm-yy")

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
        For I = 1 To 3
            .SendMail Array(Arr), _
            "Overzicht TOUR de FRANCE " & Format(Now, "yyyy")
            ‘Hier moet nog een .Body komen 
            ‘ “Hallo, ziehier de uitslag van “ & Format(Now, “dddd dd mmm yyyy”)
            If Err.Number = 0 Then Exit For
        Next I
        On Error GoTo 0
        .Close SaveChanges:=False
    End With

    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr
    
   Sheets(Array("Tussen-Eindklassement (2)", "Prijzenverdeling (2)")).Delete  ' deze is derbij gezet
   
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .DisplayAlerts = True
    End With
End Sub

Groetjes Danny.
 
Ik had een lekker weekendje in een huisje in Nunspeet (Veluwe) zónder internet, dus liet ik ff verstek gaan. Nu net thuis en nog ff mail checken. Als je nog geen verdere definitieve oplossing hebt, ga ik morgen weer meespelen... :D

Groet, Leo
 
Danny, bij gebruik van Sendmail kan je helaas geen Body toevoegen aan je mail :eek:
 
Beste Warme bakkertje ;)

Danny, bij gebruik van Sendmail kan je helaas geen Body toevoegen aan je mail :eek:

Bestaat er dan een mogelijkheid om alles in Outlook te plaatsen zonder het te verzenden, en dat ik daarna een body aan toevoeg en verzend ?

Groetjes Danny. :thumb:
 
Danny , pas je instellingen van outlook aan , haal het vinkje weg bij direct verzenden , dan blijft de mail in je postvak uit staan . Nadien moet je wel zelf op verzenden/ontvangen drukken en dit voor alle mails dat je dan gaat verzenden :eek:
 

Bijlagen

  • dannyoutlook.png
    dannyoutlook.png
    66,6 KB · Weergaven: 77
Deze komt ook van de site van Ron de Bruin,

Ik heb jouw code erin gezet,
krijg hem alleen niet werkend met een array want die functie snap ik (nog) niet.
verder temp folder aangepast omdat ie anders niet werkte op mijn computer.

Code:
Sub Mail_Sheets_Array4_Trucker10()

'Working in 97-2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim sh As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window
    Dim I As Long
    Dim rng As Range, Arr() As String, N As Integer, cell As Range
    Dim Source As Range
    Dim Dest As Workbook
    Dim wb As Workbook
    Dim OutApp As Object
    Dim OutMail As Object

    Set Source = Nothing
'    On Error Resume Next
    
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    Set Sourcewb = ActiveWorkbook
    Set rng = Sourcewb.Sheets("E-mailadressen").Range("Maillist")
    ReDim Preserve Arr(1 To rng.Cells.Count)
    N = 0
    For Each cell In rng
        If cell.Value Like "?*@?*.?*" Then
            N = N + 1
            Arr(N) = cell.Value
        End If
    Next cell
    ReDim Preserve Arr(1 To N)
    End With
  
    Sheets(Array("Tussen-Eindklassement", "Prijzenverdeling")).Copy Before:=Sheets(1) ' dit stukje is derbij gezet
    Sheets("Prijzenverdeling (2)").Select
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    
    Sheets("Tussen-Eindklassement (2)").Select
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    
'
'   On Error Resume Next
    Set Sourcewb = ActiveWorkbook

    'Copy the sheets to a new workbook
    'We add a temporary Window to avoid the Copy problem
    'if there is a List or Table in one of the sheets and
    'if the sheets are grouped
   
    With Sourcewb
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        .Sheets(Array("Tussen-Eindklassement (2)", "Prijzenverdeling (2)")).Copy
    End With

    'Close temporary Window
    TempWindow.Close

    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2010, we exit the sub when your answer is
            'NO in the security dialog that you only see  when you copy
            'an sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    '    'Change all cells in the worksheets to values if you want
        For Each sh In Destwb.Worksheets
            sh.Select
            With sh.UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
            Destwb.Worksheets(1).Select
        Next sh

    'Save the new workbook/Mail it/Delete it
    TempFilePath = "c:\test\" 'aangepast omdat het anders niet op mijn computer werkte
    TempFileName = "Overzicht TOUR de FRANCE " & Format(Now, "dd-mmm-yy")
    

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum

          With OutMail
            .To = "Naam@Provider.nl/be" 'Ik weet niet hoe de functie array werkt
            .CC = ""
            .BCC = ""
            .Subject = "Het werkt!!!!!!"
            .Body = ThisWorkbook.Sheets("e-mailadressen").Range("a5")
            .Attachments.Add (TempFilePath & TempFileName & FileExtStr)
            ' You can add other files by uncommenting the following statement.
            '.Attachments.Add ("C:\test.txt")
            
            ' In place of the following statement, you can use ".Display" to
            ' display the e-mail message.
            .Send
        End With
        
'        On Error GoTo 0
 .Close SaveChanges:=False
    

    Kill (TempFilePath & TempFileName & FileExtStr)

    Set OutMail = Nothing
    Set OutApp = Nothing
'
'
'        On Error GoTo 0
    End With

    'Delete the file you have send
    'Kill TempFilePath & TempFileName & FileExtStr
    
   Sheets(Array("Tussen-Eindklassement (2)", "Prijzenverdeling (2)")).Delete  ' deze is derbij gezet
   
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .DisplayAlerts = True
    End With
End Sub


Niels
 
Laatst bewerkt:
Beste Niels28 ;)

Ook hier krijg ik foutmeldingen.

Toch bedankt om het meedenken.

Groetjes Danny. :thumb:
 
kan je anders eens een bestandje met de laatste stand van zaken tonen. Ik vind nergens die 2 tabbladen waarvan melding wordt gemaakt.
die Arr() maakt gewoon een array aan met alle geldige emailadressen, heb je wel geldige emailadressen in je bereik staan ? check anders met ubound(arr)>=1
normaal werkt dat probleemloos.
was die constructie van mij niet eenvoudiger voor het kopieren van die 2 tabbladen ?
 
Code:
Sub Mail_Sheets_Array4_Trucker10()
'Working in 97-2010
    Dim FileExtStr As String, FileFormatNum As Long
    Dim Sourcewb As Workbook, Destwb As Workbook
    Dim TempFilePath As String, TempFileName As String
    Dim sh As Worksheet, I As Long, strto As String
    Dim TheActiveWindow As Window, TempWindow As Window
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .DisplayAlerts = False
    Set Sourcewb = ActiveWorkbook
    On Error Resume Next
    For Each cell In ThisWorkbook.Sheets("E-mailadressen") _
        .Range("A1:A10").Cells.SpecialCells(xlCellTypeConstants)
        If cell.Value Like "?*@?*.?*" Then
            strto = strto & cell.Value & ";"
        End If
    Next cell
    On Error GoTo 0
    If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)
    Sheets(Array("Tussen-Eindklassement", "Prijzenverdeling")).Copy Before:=Sheets(1) ' dit stukje is derbij gezet
    Sheets("Prijzenverdeling (2)").Select
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    
    Sheets("Tussen-Eindklassement (2)").Select
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    Set Sourcewb = ActiveWorkbook
    'Copy the sheets to a new workbook
    'We add a temporary Window to avoid the Copy problem
    'if there is a List or Table in one of the sheets and
    'if the sheets are grouped
   With Sourcewb
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        .Sheets(Array("Tussen-Eindklassement (2)", "Prijzenverdeling (2)")).Copy
    End With
    'Close temporary Window
    TempWindow.Close
    Set Destwb = ActiveWorkbook
    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2010, we exit the sub when your answer is
            'NO in the security dialog that you only see  when you copy
            'an sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With
    'Change all cells in the worksheets to values if you want
        For Each sh In Destwb.Worksheets
            sh.Select
            With sh.UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
            Destwb.Worksheets(1).Select
        Next sh
    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Overzicht TOUR de FRANCE " & Format(Now, "dd-mmm-yy")
    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
        With OutMail
            .To = strto 'Ik weet niet hoe de functie array werkt
            .CC = ""
            .BCC = ""
            .Subject = "Overzicht TOUR de FRANCE " & Format(Now, "yyyy")
            .Body = "Wijzig indien nodig deze boodschap"
            .Attachments.Add (TempFilePath & TempFileName & FileExtStr)
            '.Send
            .Display
        End With
        On Error GoTo 0
        .Close SaveChanges:=False
    End With
    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr
    Sheets(Array("Tussen-Eindklassement (2)", "Prijzenverdeling (2)")).Delete  ' deze is derbij gezet
        .ScreenUpdating = True
        .EnableEvents = True
        .DisplayAlerts = True
    End With
End Sub
 
Beste Warme beakertje ;)

Dit is al heel wat beter :thumb:

Is er nu nog een mogelijkheid om de tabbladen dynamisch te maken door in kolom C van tabblad "E-mailadressen" de tabbladen in te geven die moeten verstuurd worden.

Zoniet, neem ik deze code.

Groetjes Danny. :thumb:
 
't Zal voor morgen worden denk ik, ga nu nog wat slapen en vanavond naar Joe Cocker :p
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan