[R] Word 2007 - Envoyer Email avec sujet texte destinataire
Posté : mar. 19 mai 2015 10:43
par jcaspar
B
onjour à tous !
Je souhaiterais pouvoir envoyer un émail à partir du document en cours
en définissant le sujet, l'adresse émail du ou des destinataires ainsi que le texte à insérer
et la pièce jointe ...
$word.ActiveDocument.SendMail permet d'ouvrir outlook mais je ne parviens pas à définir un sujet
ni l'adresse email du destinataire .... faudrait il créer un objet Outlook et partir de là ?
En vous remerciant pour vos conseils
Jean-Marc
Je souhaiterais pouvoir envoyer un émail à partir du document en cours
en définissant le sujet, l'adresse émail du ou des destinataires ainsi que le texte à insérer
et la pièce jointe ...
$word.ActiveDocument.SendMail permet d'ouvrir outlook mais je ne parviens pas à définir un sujet
ni l'adresse email du destinataire .... faudrait il créer un objet Outlook et partir de là ?
En vous remerciant pour vos conseils
Jean-Marc
► Afficher le texte
Code : Tout sélectionner
#AutoIt3Wrapper_Run_Debug_Mode=Y ;(Y/N) Run Script with console debugging. Default=N
#AutoIt3Wrapper_Run_Debug=On ;(On/Off) Switch debugging on/off
local $nom = "Le nom d'utilisateur est " & @username
local $ip = "L'adresse IP du PC est :" & @IPAddress1
local $domaine = "Vous êtes connecté au domaine:" & @LogonDomain
local $serveur = "Vous êtes connecté au serveur:" & @LogonServer
local $os = "Votre système d'exploitation est le suivant :" & @OSVersion & @LF & " La langue est " & @OSlang & @LF & "Le service Pack est: " & @OSServicePack
Global $wdColorRed
$word = ObjCreate("Word.Application")
$word.helpTool()
$word.visible = True
$word.Selection.WholeStory
$word.Documents.Add
$word.Selection.TypeText($nom)
$word.Selection.WholeStory
$word.Selection.Style = "Titre"
$word.Selection.insert
$word.Selection.TypeText($ip)
$word.Selection.Style = "Titre 1"
$word.Selection.TypeParagraph
$word.Selection.TypeText($nom)
$word.Selection.Style = "Titre 2"
$word.Selection.TypeParagraph
$word.Selection.TypeText($domaine)
$word.Selection.Style = "Titre 3"
$word.Selection.TypeParagraph
$word.Selection.TypeText($serveur)
$word.Selection.Style = "Titre 4"
$word.Selection.TypeParagraph
$word.Selection.TypeText($os)
$word.Selection.Style = "Titre 5"
$word.Selection.TypeParagraph
;~ tableau automatique
$word.ActiveDocument.Tables.Add($word.Selection.Range, 5, 7)
With $word.Selection.Tables(1)
If .Style <> "Grille du tableau" Then
.Style = "Grille du tableau"
EndIf
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
EndWith
for $i = 0 to 34 step 1
$j = $i + 5 *2 /3
$word.Selection.TypeText("La valeur de la cellule " & $i & "est de" & $j)
sleep(100)
$word.Selection.MoveRight(1)
$word.Selection.Font.Color = $wdColorRed
$word.Selection.Font.Color($wdColorRed)
Next
$word.Selection.TypeParagraph
$word.Selection.TypeText(" ")
;~ tableau manuel
$word.ActiveDocument.Tables.Add($word.Selection.Range, 5, 7)
With $word.Selection.Tables(1)
If .Style <> "Grille du tableau" Then
.Style = "Grille du tableau"
EndIf
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
EndWith
$word.Selection.TypeText("Leo")
$word.Selection.Font.ColorIndex = 10
$word.Selection.MoveRight(1)
$word.Selection.TypeText("Firmin")
$word.Selection.Font.Color(5)
$word.Selection.MoveRight(1)
$word.Selection.Font.Color = "wdColorRed"
$word.Selection.TypeText("Louis")
$word.Selection.MoveRight(1)
$word.Selection.TypeText("Elise")
$word.Selection.MoveRight(1)
$word.Selection.TypeText("Lucie")
$word.Selection.MoveRight(1)
$word.Selection.TypeText("Tom")
$word.Selection.MoveRight(1)
$word.Selection.TypeText("Jules")
$word.Selection.MoveRight(1)
$word.Selection.MoveLeft
$word.Selection.MoveDown
$word.Selection.TypeText("Lupita")
$word.Selection.MoveDown
$word.Selection.MoveDown
$word.Selection.MoveDown
$word.Selection.MoveDown
$word.Selection.MoveDown
$word.ActiveDocument.Tables(1).Cell(1, 1).Range.Shading.BackgroundPatternColor("wdColorAqua")
;~ local $msoShapeRectangle
;~ $word.ActiveDocument.Shapes.AddShape($msoShapeRectangle, 122.25, 599.25, 229.5, 55.5).Select
;~ $word.Selection.ShapeRange.Fill.Solid
;~ $word.Selection.ShapeRange.Fill.ForeColor.ObjectThemeColor = "wdThemeColorAccent2"
;~ $word.Selection.ShapeRange.Fill.ForeColor.TintAndShade = "0#"
;~ $word.Selection.ShapeRange.Fill.BackColor.RGB(255, 255, 255)
;~ $word.Selection.ShapeRange.Fill.Visible = "msoTrue"
;~ $word.Selection.ShapeRange.Line.ForeColor.ObjectThemeColor = "wdThemeColorMainLight1"
;~ $word.Selection.ShapeRange.Line.ForeColor.TintAndShade = "-0.05"
;~ $word.Selection.ShapeRange.Line.Weight = "3#"
;~ $word.Selection.ShapeRange.Line.Style = "msoLineSingle"
;~ $word.Selection.ShapeRange.Line.Visible = "msoTrue"
;~ $word.Selection.ShapeRange.Shadow.Type = "msoShadow3"
;~ $word.Selection.ShapeRange.Shadow.ForeColor.ObjectThemeColor = "wdThemeColorAccent2"
;~ $word.Selection.ShapeRange.Shadow.ForeColor.TintAndShade = "-0.5"
;~ $word.Selection.ShapeRange.Shadow.Transparency = "0.5"
;~ $word.Selection.ShapeRange.Shadow.OffsetX = "1#"
;~ $word.Selection.ShapeRange.Shadow.OffsetY = "2#"
;~ $word.Selection.ShapeRange.Shadow.Visible = "msoTrue"
;~ $word.Selection.ShapeRange.ThreeD.Visible = "msoFalse"
;~ $word.Hyperlinks.Add($oAnchor, $sAddress, $sSubAddress, $sScreenTip, $sTextToDisplay, $sTarget)
;~ $word.ActiveDocument.Shapes.AddShape(1, 95.25, 78.75, 285.75, 146.25).Select;msoShapeRectangle = 1
;~ $word.Selection.ShapeRange.Fill.Solid
;~ $word.Selection.ShapeRange.Fill.ForeColor.ObjectThemeColor = 4 ;wdThemeColorAccent1 = 4
;~ $word.Selection.ShapeRange.Fill.ForeColor.TintAndShade = 0.4
;~ ToolTip("Etape 1", 100, 300)
;~ Sleep(2000)
;~ $word.Selection.ShapeRange.Fill.BackColor.ObjectThemeColor = 2
;~ $word.Selection.ShapeRange.Fill.BackColor.TintAndShade = 0.8
;~ $word.Selection.ShapeRange.Fill.Visible = -1;msoTrue = -1
;~ $word.Selection.ShapeRange.Fill.TwoColorGradient(1, 1)
;~ ToolTip("Etape 2", 100, 300)
;~ Sleep(2000)
;~ $word.Selection.ShapeRange.Line.ForeColor.ObjectThemeColor = 1
;~ $word.Selection.ShapeRange.Line.ForeColor.TintAndShade = -0.05
;~ $word.Selection.ShapeRange.Line.Weight = 3
;~ $word.Selection.ShapeRange.Line.Style = 1 ;msoLineSingle = 1
;~ $word.Selection.ShapeRange.Line.Visible = -1
;~ ToolTip("Etape 3", 100, 300)
;~ Sleep(2000)
;~ $word.Selection.ShapeRange.Shadow.Type = 3
;~ $word.Selection.ShapeRange.Shadow.ForeColor.ObjectThemeColor = 4
;~ $word.Selection.ShapeRange.Shadow.ForeColor.TintAndShade = -0.5
;~ $word.Selection.ShapeRange.Shadow.Transparency = 0.5
;~ $word.Selection.ShapeRange.Shadow.OffsetX = 1
;~ $word.Selection.ShapeRange.Shadow.OffsetY = 2
;~ $word.Selection.ShapeRange.Shadow.Visible = -1
;~ ToolTip("Etape 4", 100, 300)
;~ Sleep(2000)
;~ $word.Selection.ShapeRange.ThreeD.Visible = -1
;~ ToolTip("Etape 5", 100, 300)
;~ Sleep(2000)
;~ $word.Selection.ShapeRange.TextFrame.TextRange.Select
;~ $word.Selection.Collapse
;~ $word.Selection.TypeText("Ici le texte")
;~ $word.Selection.ParagraphFormat.Alignment = 1 ; wdAlignParagraphCenter = 1
;~ $word.Selection.TypeParagraph
;~ $word.Selection.InlineShapes.AddPicture("D:\Utilisateurs\Public\Pictures\Sample Pictures\Desert.jpg", 0, 1)
;~ $word.showMe
msgbox(64,"test"," Le nom du createur est "&$word.Creator &@LF & "Le nom d'utilisateur est "&$word.UserName &@LF & "L'imprimante active est" &$word.ActivePrinter& @lf &"Le nom du produit utilisé est"&$word.ProductCode &$word.MailSystem )
;~ $word.PrintOut
msgbox(64,"test",$word.GetDefaultTheme(1))
msgbox(64,"toto",$word.ListCommands)
sleep(500)
$word.CheckSpelling()
$word.CheckGrammar()
$word.ActiveDocument.SendMail
$word.ActiveDocument.SendMailAttach = True
$word.ActiveDocument.Subject("test mail")
;~ $word.ChangeFileOpenDirectory ("D:\Utilisateurs\jcaspar\Desktop\")
;~ $word.ActiveDocument.SaveAs ("test.docx")
;~ $word.objMailIt.Attachments.Add($word.ActiveDocument.FullName)
;~ $word.objMailIt.To("jeanmarc.caspar@gmail.com")
;~ $word.objMailIt.Subject = $word.ActiveDocument.Name
;~ $word.objMailIt.BodyFormat =1
;~ $word.objMailIt.Body = $word.ActiveDocument.Range
;~ [b]$word.ActiveDocument.Subject = "Test Sujet"[/b]
;~ [b]$word.ActiveDocument.Body = "Le texte à ajouter "[/b]
;~ $word.ActiveDocument.Attachments.Add($word.ThisDocument.Path & "\" & $word.ThisDocument.Name)
;~ [b]$word.ActiveDocument.$word.to("test@test.fr")[/b]
;~ $word.Printout
$word.quit