• 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.

Mailen sheets excel 2003 vs excel 2007

  • Onderwerp starter Onderwerp starter MMV
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

MMV

Gebruiker
Lid geworden
6 mei 2008
Berichten
111
Beste leden,

ik gebruik reeds een tijd de mailcode van R de Bruin.
Nu ben ik overgestapt naar excel 2007, de code werkt nu niet meer naar behoren.
Er blijven nu steeds links bestaan tussen de sheets welke ik mail en mijn originele werkmap. Dit onderving ik door de volgende code.

Code:
    Set wb = ActiveWorkbook

    WorkbookLinks = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
    If IsArray(WorkbookLinks) Then
      For I = LBound(WorkbookLinks) To UBound(WorkbookLinks)
          wb.BreakLink _
                  Name:=WorkbookLinks(I), _
                  Type:=xlLinkTypeExcelLinks
      Next I
    'Else
      'MsgBox "No Links to other workbooks"
    End If

Deze code verwijdert echter ook de gegevens welke ik in mijn grafieken wil laten zien. Zonder deze code blijven er verwijzingen in zitten........! Wie weet raad?
 
Laatst bewerkt:
De complete macro ziet er als onderstaand uit. hierbij komen er problemen met links in de grafieken.

Code:
Sub Mail_Sheets_Array()
'Working in 2000-2007
    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 OutApp As Object
    Dim OutMail As Object
    Dim sh As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window
    
    Dim Links As Variant
    Dim i As Integer

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

    Sheets("Blad 1").Select
    ActiveSheet.Unprotect
    Sheets("Blad 2").Select
    ActiveSheet.Unprotect

    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("Blad 1", "Blad 2", "Blad 3")).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, 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

Set wb = ActiveWorkbook

With ActiveWorkbook
    Links = .LinkSources(xlExcelLinks)
    If Not IsEmpty(Links) Then
        For i = 1 To UBound(Links)
            .BreakLink Links(i), xlLinkTypeExcelLinks
        Next i
    End If
End With



    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Part of " & Sourcewb.Name & " " _
                 & Format(Now, "dd-mmm-yy h-mm-ss")

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

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
        With OutMail
            .To = "ron@debruin.nl"
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = "Hi there"
            .Attachments.Add Destwb.FullName
            'You can add other files also like this
            '.Attachments.Add ("C:\test.txt")
            .Display   'or use .send
        End With
        On Error GoTo 0
        .Close SaveChanges:=False
    End With

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

    Set OutMail = Nothing
    Set OutApp = Nothing
    
    Sheets("Blad 1").Select
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    Sheets("Blad 2l").Select
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    


    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 
Niemand die hier iets zinnigs over kan zeggen?
 
Onderstaande macro zet de grafieken om in een afbeelding zodat wel de gegevens behouden blijven maar de links wel verbroken worden. Misschien helpt dit je verder.
Code:
Sub Charts2Pics()
    Dim objCht As ChartObject, shtTemp As Worksheet, objTemp As Object
    For Each shtTemp In ActiveWorkbook.Worksheets
        For Each objCht In shtTemp.ChartObjects
            objCht.CopyPicture xlScreen, xlPicture
            Set objTemp = shtTemp.Pictures.Paste
            objTemp.Left = objCht.Left
            objTemp.Top = objCht.Top
            objCht.Delete
        Next
    Next
    Set objTemp = Nothing
End Sub
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan