Accueil > > > PILOTER OUTLOOK ET WORD DEPUIS UNE APPLICATION; COPIER UN CONTENT WORD DANS UN MAIL OUTLOOK
PILOTER OUTLOOK ET WORD DEPUIS UNE APPLICATION; COPIER UN CONTENT WORD DANS UN MAIL OUTLOOK
Information sur la source
Description
petit code simple qui permet de piloter outlook 2003 et word 2003. il copie le contenu d'un document word dans le corps de mail d'outlook, pret à être envoyé. Attention, il faut mettre les référence d'outlook et de word dans le projet
Source
- Imports Microsoft.Office.Interop
- 'this example need reference of microsoft word object library and outlook object library
-
- Public Class Form1
-
- Private oMissing As Object = System.Reflection.Missing.Value
-
- Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
- Dim strSubject As String = "subject test"
- Dim strMessage As String = "message test"
- Dim astrRecip As String = "recipientMe@mail.org"
- Dim astrAttachments As String = txtPath.Text
-
- Dim OutlookApp As New Outlook.Application
- Dim MyEMail As Outlook.MailItem = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
-
- For Each Recipient As String In Split(astrRecip, ";") : MyEMail.Recipients.Add(Recipient) : Next
- For Each Attachment As String In Split(astrAttachments, ";") : MyEMail.Attachments.Add(Attachment) : Next
-
- MyEMail.Subject = strSubject
- MyEMail.HTMLBody = getWordDoc(astrAttachments)
-
- MyEMail.Display()
- End Sub
-
- Private Function getWordDoc(ByVal filename As String) As Object
- Dim wordApp As Word.Application = New Word.ApplicationClass()
- Dim wordDoc As Word._Document
- Dim content As Object = ""
-
- wordApp.Visible = False
-
- wordDoc = wordApp.Documents.Open(CType(filename, Object), oMissing, True, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
-
- wordDoc.Content.Select()
- wordDoc.Content.Copy()
-
- Dim objClipboard As IDataObject = Clipboard.GetDataObject()
- If objClipboard.GetDataPresent(DataFormats.Html) Then content = objClipboard.GetData(DataFormats.Html)
-
- wordApp.Quit(CType(False, Object), oMissing, oMissing)
-
- wordDoc = Nothing
- wordApp = Nothing
- Return content
- End Function
- End Class
Imports Microsoft.Office.Interop
'this example need reference of microsoft word object library and outlook object library
Public Class Form1
Private oMissing As Object = System.Reflection.Missing.Value
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
Dim strSubject As String = "subject test"
Dim strMessage As String = "message test"
Dim astrRecip As String = "recipientMe@mail.org"
Dim astrAttachments As String = txtPath.Text
Dim OutlookApp As New Outlook.Application
Dim MyEMail As Outlook.MailItem = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
For Each Recipient As String In Split(astrRecip, ";") : MyEMail.Recipients.Add(Recipient) : Next
For Each Attachment As String In Split(astrAttachments, ";") : MyEMail.Attachments.Add(Attachment) : Next
MyEMail.Subject = strSubject
MyEMail.HTMLBody = getWordDoc(astrAttachments)
MyEMail.Display()
End Sub
Private Function getWordDoc(ByVal filename As String) As Object
Dim wordApp As Word.Application = New Word.ApplicationClass()
Dim wordDoc As Word._Document
Dim content As Object = ""
wordApp.Visible = False
wordDoc = wordApp.Documents.Open(CType(filename, Object), oMissing, True, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
wordDoc.Content.Select()
wordDoc.Content.Copy()
Dim objClipboard As IDataObject = Clipboard.GetDataObject()
If objClipboard.GetDataPresent(DataFormats.Html) Then content = objClipboard.GetData(DataFormats.Html)
wordApp.Quit(CType(False, Object), oMissing, oMissing)
wordDoc = Nothing
wordApp = Nothing
Return content
End Function
End Class
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Word et Outlook [ par guycnoel ]
Je réussis sans problème à créer dans Word une petite macro qui crée un mail dans Outlook par le code suivant : Set myApp = CreateObject("Outlook.Appl
Comment attacher un fichier à un message mail outlook généré par une macro depuis word ? [ par julitoVB ]
Salut,j'ai crée depuis word une macro permettant de générer un mail Outlook et de l'envoyer. Cependant depuis la macro word j'aimerai insérer un fichi
envoyer un mail via word/outlook [ par dg69 ]
Bonsoir,je débute en la matière, mais je souhaiterais savoir s'il est possible à partir de word, d'envoyer automatiquement un document
Mettre le focus sur le corps d'un mail [ par prady92 ]
Bonjour,Une petite question sur l'envoi d'un mail via Outlook.Contexte :Via un formulaire ACCESS, j'ouvre un fichier Word qui m'est fourni avec du tex
Publipostage en VBA dans Outlook [ par Renarde ]
Bonjour, je suis tellement débutant que j'en ai honte. Je cherche à faire du publipostage à partir d'Outlook. Les solutions proposée
Envoie de mail à partir d'excel avec Outlook [ par AiDuK ]
Bonjour à toutes et à tous.je suis actuellement en trainde travailler sur un envoie de mail à partir d'un clique, qui reprendrait les informations con
VBA Outlook Programme Archiver Mails [ par kinslow ]
Bonjour, Je travail dans un cabinet d'architecte et je recoit bqc de mails par jours. En plus il m'est obligé de les enregistrer pour les sauvegarde
envoye mail avec access [ par imsse ]
voici mon probleme , je souhaite envoyer un mail outlook avec access sur le clik d'un bouton mais lerreur " echec d'excution" s'affcihe a cette ligne
Version OUTLOOK ou OUTLOOK EXPRESS [ par jimy neutron ]
Bonjour à tous,Voilà! Je developpe actuellement un annuaire ( ou répertoire ) ciblé recherche d'emploi (Un outils que j'aurais aimé avoir à une époque
|
Derniers Blogs
XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|