Office: (Office 2016) PDF als E-Mail Anhang nur die erste Seite

Helfe beim Thema PDF als E-Mail Anhang nur die erste Seite in Microsoft Word Hilfe um das Problem gemeinsam zu lösen; Hallo liebes Forum, Den u. s. Code habe ich mir zusammengebastelt. Das Makro sorgt dafür, dass die Datei als PDF in eine neue E-Mail angehängt wird.... Dieses Thema im Forum "Microsoft Word Hilfe" wurde erstellt von beBerlin, 14. März 2023.

  1. beBerlin Neuer User

    PDF als E-Mail Anhang nur die erste Seite


    Hallo liebes Forum,
    Den u. s. Code habe ich mir zusammengebastelt.
    Das Makro sorgt dafür, dass die Datei als PDF in eine neue E-Mail angehängt wird. Außerdem werden noch Betreff und Text gefüllt. Die Empfänger Adresse wird je angekreuztem Feld gefüllt.

    Es wird das ganze Dokument in ein PDF umgewandelt.
    Besteht die Möglichkeit, dass nur die erste Seite in ein PDF umgewandelt wird?

    VG
    Mark




    Code:
    Option Explicit
    Public Sub An_PS_2_senden()
      Dim objDoc As Document
      Dim objOL As Object
      Dim objMail As Object
      Dim colMailInfos As Collection
      Dim objMailInfo As clsMailInfo
      Dim strSignature As String
      Dim strPDFPath As String
      Dim blnOLNewInstance As Boolean
     
      Set objDoc = ActiveDocument
     
      If objDoc.Path = "" Then
          MsgBox "Dokument muss erst gespeichert werden!", vbExclamation
          Exit Sub
      End If
    
      ' Init Outlook
      On Error Resume Next
      Set objOL = GetObject(, "Outlook.Application")
      If Err.Number <> 0 Then
        Set objOL = CreateObject("Outlook.Application")
        blnOLNewInstance = True
      End If
      On Error GoTo 0
     
      ' Get MailInfos
      Set colMailInfos = GetMailInfos(objDoc)
     
      ' Get Signature
     '  strSignature = LoadSignatureFromFile()
     
    '   If Len(strSignature) = 0 Then
    '     MsgBox "Signaturdatei konnte nicht geladen werden!", vbInformation + vbOKOnly, "Hinweis"
    '   End If
     
      ' Temporary caching of the document as a PDF file for use as an attachment
      strPDFPath = SaveToPDF(objDoc)
     
      ' Create and send all requested mails
      For Each objMailInfo In colMailInfos
        
        Set objMail = objOL.CreateItem(0)       ' olMailItem
        ComposeMail objMail, objMailInfo, strPDFPath, strSignature
        objMail.Display
      Next
     
      ' Remove attachment file
      On Error Resume Next
      Kill strPDFPath
      On Error GoTo 0
     
      ' Cleanup
      Set objMail = Nothing
      Set objMailInfo = Nothing
      Set colMailInfos = Nothing
      Set objOL = Nothing
      Set objDoc = Nothing
    End Sub
    
    ' -----------------------------------------------------------------------------
    ' Private methods
    ' -----------------------------------------------------------------------------
    Private Function GetMailInfos(ByVal pDoc As Document) As Collection
      Dim colMailInfos As Collection
      Dim objFF As FormField
      Dim objMailInfo As clsMailInfo
      Dim astrStatusText() As String
     
      Set colMailInfos = New Collection
        
      For Each objFF In pDoc.FormFields
        If objFF.Type = wdFieldFormCheckBox And objFF.Result = "1" Then
          
          On Error GoTo MailInfos_Err
          
          Set objMailInfo = New clsMailInfo
          objMailInfo.ControlName = objFF.Name
          
          astrStatusText = Split(objFF.StatusText, "~")
          objMailInfo.MailAddr = Trim(astrStatusText(0))
          objMailInfo.Salutation = Trim(astrStatusText(1))
          colMailInfos.Add Item:=objMailInfo, Key:=objFF.Name
    
    MailInfos_Cont:
        End If
      Next
    
      Set GetMailInfos = colMailInfos
      Exit Function
     
    MailInfos_Err:
    '  MsgBox _
        "Error: Invalid Statustext" & vbCrLf _
        & "Checkbox " & objFF.Name, vbExclamation, "Fehlermeldung"
      Resume MailInfos_Cont
    End Function
    
    
    Private Function LoadSignatureFromFile() As String
      Dim objFSO As Object        ' FileSystemObject
      Dim objTsr As Object        ' TextStream
      Dim strFilename As String
     '  Dim strSignature As String
    
     '  On Error GoTo LoadSignatureFromFile_Err
     
    '   strFilename = Environ$("APPDATA") & "\Microsoft\Signatures\kurz.htm"
     
    '   Set objFSO = CreateObject("Scripting.FileSystemObject")
    '   Set objTsr = objFSO.OpenTextFile(strFilename, 1)          ' ForReading
    '   strSignature = objTsr.ReadAll
    '   objTsr.Close
     '  LoadSignatureFromFile = strSignature
    
    ' LoadSignatureFromFile_Err:
      Set objTsr = Nothing
      Set objFSO = Nothing
    End Function
    
    
    Private Function SaveToPDF(ByVal pDoc As Document) As String
      Dim objFSO As Object                  ' FileSystemObject
      Dim strTempPath As String
      Dim strFilename As String
      Dim strPDFFilename As String
     
      On Error GoTo SaveToPDF_Err
     
      ' Ensure that all changes have been saved
      If Not pDoc.Saved Then pDoc.Save
     
      ' Save document as temporary PDF
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      strTempPath = objFSO.GetSpecialFolder(2).Path
      strFilename = objFSO.GetBaseName(pDoc.Name)
      strPDFFilename = objFSO.BuildPath(strTempPath, strFilename & ".pdf")
      pDoc.SaveAs2 strPDFFilename, wdFormatPDF
      SaveToPDF = strPDFFilename
    
    SaveToPDF_Err:
      Err.Clear
      Set objFSO = Nothing
    End Function
    
    Private Sub ComposeMail( _
        ByVal pMailItem As Object, _
        ByVal pMailInfo As clsMailInfo, _
        ByVal AttachmentFilePath As String, _
      ByVal Signature As String)
        
        Const cMailText As String = _
              "<p style='font-family:Type Office " & _
              "sans-serif; font-size:11pt;'>" & _
              "{0}," & "<br></br>" & "<br></br>" & _
              "Text" & "</p>"
        
        With pMailItem
          .To = pMailInfo.MailAddr
          .Subject = "Betreff XXX"
          .BodyFormat = 2                       ' olFormatHTML
          .HTMLBody = Replace(cMailText, "{0}", pMailInfo.Salutation, 1, 1)
          .HTMLBody = .HTMLBody & Signature
          .Attachments.Add AttachmentFilePath, 1
        End With
    
        Debug.Print "("; pMailInfo.ControlName; ") MailTo: <"; pMailInfo.MailAddr; "> composed!"
    End Sub
        
    
    
     
    beBerlin, 14. März 2023
    #1
  2. Gerhard H Erfahrener User
    Hallo beBerlin,

    ich hab jetzt nicht dein ganzes Opus nachvollzogen. Aber was das Speichern als PDF betrifft, würde ich statt mit der SaveAs2-Methode lieber mit der ExportAsFixedFormat-Methode arbeiten. Diese kennt den Parameter Range, wo du angeben kannst, ob du das ganze Dokument, die aktuelle Seite, oder einen (Seiten-)bereich exportieren willst.
     
    Gerhard H, 14. März 2023
    #2
Thema:

PDF als E-Mail Anhang nur die erste Seite

Die Seite wird geladen...
  1. PDF als E-Mail Anhang nur die erste Seite - Similar Threads - PDF Mail Anhang

  2. Komplexes Makro ohne Ahnung :-/

    in Microsoft Excel Hilfe
    Komplexes Makro ohne Ahnung :-/: Hallo Ihr Lieben, ich brauche ganz dringend Hilfe. Ich bin zwar mit Formeln in Excel ganz gut aufgestellt, aber mit Makros leider nicht. Ich muss für meine Eltern und mich viele Versicherungen und...
  3. Kopieren eines Anhangs eines PDF-Formulars in eine neue Mail

    in Microsoft Outlook Hilfe
    Kopieren eines Anhangs eines PDF-Formulars in eine neue Mail: Schönen guten Morgen, ich habe folgendes Problem. Ich bekomme ein PDF-Formular (Formular1.pdf) per Mail. In diesen Formular ist ein weiters Formular (Formular2.pdf) angehängt. Mit einem Makro...
  4. Makro erstellen: PDF erstellen und als Mail verschicken.

    in Microsoft Excel Hilfe
    Makro erstellen: PDF erstellen und als Mail verschicken.: Hallo, hatte vor zwei Jahren den Code geschrieben hatte auch gut funktioniert gehabt. Wollte es nun für was anderes nutzen aber dieser Makro funktioniert nicht mehr. Habe in meiner Recherche...
  5. Es sollen Spalten als PDF und Mail erstellt werden die ein Bedingung haben

    in Microsoft Excel Hilfe
    Es sollen Spalten als PDF und Mail erstellt werden die ein Bedingung haben: Hallo Ihr Profis, ich komme nicht weiter und brauch mal eure Hilfe Ich habe folgende Tabelle Spalte A (Ja/Nein) Felder, Spalte G bis D sind Adressfelder, J bis M sind Datumfelder. Bei Spalte A...
  6. Access 2013 Bericht als pdf und mail

    in Microsoft Access Hilfe
    Access 2013 Bericht als pdf und mail: Hallo mein Problem ist das ich im Formular die Daten erheben kann und wenn ich auf den Button Abschließen gehe sollte er eine PDF erstellen in einem bestimmten Ordner mit bestimmten Namen...
  7. E-Mails mit PDF-Anhang versenden ...

    in Microsoft Access Hilfe
    E-Mails mit PDF-Anhang versenden ...: Hallo zusammen, mit dem unten dargestellten Code möchte ich E-Mails mit einem PDF-Anhang aus Access 2007 Sp1 (auf einem Win-Vista-Sp1-Rechner) verschicken. Mit Access 2003 hat das auch...
  8. Anhang mit PDF wird in .pd_ umbenannt

    in Microsoft Outlook Hilfe
    Anhang mit PDF wird in .pd_ umbenannt: Hallo Zusammen, ich habe seit ein paar Tagen ein komisches Phänomen. Ich nutze die aktuelle Version von Outlook 365. Outlook hat plötzlich vor ein paar Tagen, alle Mail-Anhänge mit der Endung...
  1. Diese Seite verwendet Cookies, um Inhalte zu personalisieren, diese deiner Erfahrung anzupassen und dich nach der Registrierung angemeldet zu halten.
    Auf dieser Website werden Cookies für die Zugriffsanalyse und Anzeigenmessung verwendet.
    Wenn du dich weiterhin auf dieser Seite aufhältst, akzeptierst du unseren Einsatz von Cookies.
    Information ausblenden