Note: The other languages of the website are Google-translated. Back to English
Se connecter  \/ 
x
or
x
S'inscrire  \/ 
x

or

Comment appliquer un bouton pour envoyer un e-mail avec le fichier Word actuel en pièce jointe? 

Si vous devez envoyer un message électronique à partir d'un document Word via Outlook et joindre également le fichier Word actuel, vous pouvez créer un bouton de commande, puis envoyer le message en cliquant sur ce bouton sans ouvrir Outlook. Cet article, je vais vous présenter comment y faire face rapidement et facilement.

Appliquer un bouton pour envoyer un e-mail avec le fichier Word actuel en pièce jointe


Appliquer un bouton pour envoyer un e-mail avec le fichier Word actuel en pièce jointe

Veuillez suivre les étapes suivantes pour résoudre ce travail dans un fichier Word:

1. Tout d'abord, vous devez créer un bouton de commande, veuillez cliquer sur Développeur > Outils hérités > Bouton de commande (contrôle ActiveX), voir capture d'écran:

bouton doc pour envoyer l'email 1

2. Sélectionnez le bouton et cliquez sur Propriétés sous le Développeur onglet, dans le Propriétés volet, saisissez le texte de légende dont vous avez besoin dans le Légende champ, voir capture d'écran:

bouton doc pour envoyer l'email 2

3. Ensuite, fermez le Propriétés volet, maintenant, cliquez avec le bouton droit sur le bouton et choisissez Voir le code, voir capture d'écran:

bouton doc pour envoyer l'email 3

4. Et puis, dans l'affichage Microsoft Visual Basic pour applications fenêtre, copiez et collez le code ci-dessous entre les scripts originaux, voir capture d'écran:

Dim xOutlookObj As Object
    Dim xEmail As Object
    Dim xDoc As Document
    Application.ScreenUpdating = False
    Set xOutlookObj = CreateObject("Outlook.Application")
    Set xEmail = xOutlookObj.CreateItem(olMailItem)
    Set xDoc = ActiveDocument
    xDoc.Save
    With xEmail
        .Subject = "Fax-data"
        .Body = "This is a test email."
        .To = "yy@addin99.com"
        .Importance = olImportanceNormal
        .Attachments.Add xDoc.FullName
        .Display
    End With
    Set xDoc = Nothing
    Set xEmail = Nothing
    Set xOutlookObj = Nothing
    Application.ScreenUpdating = True

bouton doc pour envoyer l'email 4

Notes: Dans le code ci-dessus, vous devez modifier le sujet, le corps du texte ou l'adresse d'envoi selon vos besoins.

5. Ensuite, enregistrez et fermez ce code, cliquez sur Mode de conception pour désactiver le mode de conception. Maintenant, lorsque vous cliquez sur le bouton de commande que vous avez créé, un e-mail sera créé avec le document Word actuel en pièce jointe, voir capture d'écran:

bouton doc pour envoyer l'email 5

6. Enfin, il vous suffit de cliquer Envoyer bouton pour envoyer ce message.


Outils de productivité Word recommandés

 

Kutools For Word - Plus de 100 fonctionnalités avancées pour Word, économisez 50% de votre temps

  • Les opérations compliquées et répétées peuvent être effectuées une seule fois en quelques secondes.
  • Insérez simultanément plusieurs images dans des dossiers dans un document Word.
  • Fusionner et combiner plusieurs fichiers Word dans des dossiers en un seul avec l'ordre souhaité.
  • Divisez le document actuel en documents séparés selon l'en-tête, le saut de section ou d'autres critères.
  • Convertissez des fichiers entre Doc et Docx, Docx et PDF, collection d'outils pour les conversions et la sélection courantes, etc.
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Richard Bird · 1 months ago
    I have create the document but my issue  now is that if I send this form to say 4 people to complete, when they open it up from the email attachment it opens in read only mode and when they click submit it asks them to save as before it will allow the code to open an email addressed to me. Is there a way around this other than giving them the location of the file?
  • To post as a guest, your comment is unpublished.
    Chelo · 11 months ago
    Hi Extend office,

    Can we set a different email not linked to Outlook? Like direct email to GoDaddy account?

    • To post as a guest, your comment is unpublished.
      Shelby · 6 months ago
      I am trying to find out the same information. I use gmail and I need to create a form to send out to varies different email address that can automatically submit back to my gmail account. 

  • To post as a guest, your comment is unpublished.
    Jacques · 1 years ago
    Does this also work for Lotus Notes?
    What must I change in "xOutlookObj"?
  • To post as a guest, your comment is unpublished.
    Lasse Jensen · 1 years ago

    For example using text from a textbox/textfield in the Word-document, and inserting it as text in the subject line of your E-mail?

    • To post as a guest, your comment is unpublished.
      Mark Crane · 8 months ago
      Yes this is also what i'm after can anybody help with this request?
  • To post as a guest, your comment is unpublished.
    Gill Leadbetter · 1 years ago
    I'd like my document to send as a PDF document rather than a word document.

  • To post as a guest, your comment is unpublished.
    Santiago · 1 years ago
    Hi! I'd like to make the command button send an email with the Word document as the body of the email (my word document is a form). Is there a way to do that?
  • To post as a guest, your comment is unpublished.
    andrew · 1 years ago
    I had it working at first, and then for some reason now, it gives me an error of error 429 about activeX component can't create object. i literally just copied and pasted. This worked before but i just changed font size, made button bigger, and relabeled caption. i don't think i accidentally changed some other settings? any idea what it could be?
  • To post as a guest, your comment is unpublished.
    Tausif · 1 years ago
    I have made a fillable form in MS word. I have used legacy tools for calculation etc. I have also added a submit button which works to send the form to email. The problem is that when I reopen this document after saving, it does not work. I have even tried saving it as macro enabled document but no use. Can you please help ?
    Thanks
  • To post as a guest, your comment is unpublished.
    Don Patterson · 1 years ago
    Can this be done so you only send one page of a document?
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Don,
      To deal with your task, please apply the below code,in the code, you should change the start page and end page to your own:

      Private Sub CommandButton1_Click()
      Dim xCurPageStart As Long, xCurPageEnd As Long, xCurPageRange As Range
      Dim xCurPage As Integer, xPages As Integer
      Dim xOutlookObj As Object
      Dim xEmail As Object
      Dim xDoc As Document, xNewDoc As Document
      Dim xFilePath As String
      Dim xOldStart As Long, xOldEnd As Long
      On Error Resume Next
      Application.ScreenUpdating = False
      Set xOutlookObj = CreateObject("Outlook.Application")
      Set xEmail = xOutlookObj.CreateItem(olMailItem)
      xFilePath = CreateObject("WScript.Shell").SpecialFolders(16)
      Set xDoc = ActiveDocument
      xOldStart = xDoc.Application.Selection.Start
      xOldEnd = xDoc.Application.Selection.End
      xDoc.Save
      xFilePath = xFilePath + "\attached file" + VBA.Mid(xDoc.FullName, VBA.InStrRev(xDoc.FullName, ".")) 'attached file is the attachment file name,change to your need
      xCurPageStart = 2 'start page
      xCurPageEnd = 2 'end page
      xPages = Selection.Information(wdNumberOfPagesInDocument)
      xCurPageStart = Selection.GoTo(what:=wdGoToPage, Which:=wdGoToNext, Name:=xCurPageStart).Start
      If xCurPage = xPages Then
      xCurPageEnd = ActiveDocument.Content.End
      Else
      xCurPageEnd = Selection.GoTo(what:=wdGoToPage, Which:=wdGoToNext, Name:=xCurPageEnd + 1).Start
      End If
      Set xCurPageRange = ActiveDocument.Range(xCurPageStart, xCurPageEnd)
      xCurPageRange.Select
      xCurPageRange.Copy
      Set xNewDoc = Application.Documents.Add(Visible:=False)
      xNewDoc.Activate
      xNewDoc.Content.PasteAndFormat wdFormatOriginalFormatting
      xNewDoc.SaveAs2 FileName:=xFilePath
      xNewDoc.Close
      xDoc.Range(xOldStart, xOldEnd).Select
      With xEmail
      .Subject = "Fax-data"
      .Body = "This is a test email."
      .To = "yy@addin99.com"
      .Importance = olImportanceNormal
      .Attachments.Add xFilePath
      .Display
      End With
      VBA.Kill xFilePath
      Set xDoc = Nothing
      Set xEmail = Nothing
      Set xOutlookObj = Nothing
      Application.ScreenUpdating = True
      End Sub
  • To post as a guest, your comment is unpublished.
    Abhi · 1 years ago
    Hi Extend Office Team,

    I believe 'xEmile' is misspelt. It should be 'xEmail'.

    While the code runs and there is no issue, the following statement will do nothing:

    Set xEmail = Nothing
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi,Abhi,
      Thank you for your comment, as you said, the 'xEmile' is misspelt, it should be 'xEmail'. I have updated the code.
      Thank you again!
  • To post as a guest, your comment is unpublished.
    Alondra · 2 years ago
    Hola, me podrían apoyar para que el archivo se convierta en PDF y se adjunte al correo en ves del word por favor.
    Muchas gracias.
  • To post as a guest, your comment is unpublished.
    Nichole · 2 years ago
    I am trying to have the email send with the subject line being the contents of one of my fields. Is this possible?