Sub test()
fichier$ = "C:\Users\patrick\Desktop\toto.htm"
dossier$ = Replace(fichier, ".htm", "_fichiers")
cde = GetCodeWithSrcRacourci(fichier)
I = FreeFile: Open (Replace(fichier, ".htm", "2.htm")) For Output As #I: Print #I, cde: Close #I
'SendSelectionWithOutlook cde, dossier, 2
End Sub
Function GetCodeWithSrcRacourci(fichier$)
Dim docHtml As New HTMLDocument
Dim laChaine As String, x
x = FreeFile: Open fichier For Binary Access Read As #x: laChaine = String(LOF(x), " "): Get #x, , laChaine: Close #x
docHtml.body.innerHTML = laChaine
styl = "<style id=" & Split(Split(laChaine, "<style id=")(1), "</style>")(0) & "</style>"
Set elements = docHtml.getElementsByTagName("*")
For Each elem In docHtml.all
If elem.tagName = "shape" Then elem.ParentNode.RemoveChild (elem)
If elem.tagName = "AutoPict" Then elem.ParentNode.RemoveChild (elem)
If elem.tagName = "imagedata" Then elem.ParentNode.RemoveChild (elem)
If elem.tagName = "lock" Then elem.ParentNode.RemoveChild (elem)
If elem.tagName = "!" Then elem.ParentNode.RemoveChild (elem)
If elem.tagName = "SizeWithCells" Then elem.ParentNode.RemoveChild (elem)
If elem.tagName = "CF" Then elem.ParentNode.RemoveChild (elem)
If elem.tagName = "ClientData" Then elem.ParentNode.RemoveChild (elem)
If LCase(elem.tagName) = "img" Then elem.ParentNode.RemoveChild (elem)
'If LCase(elem.tagName) = "span" Then elem.ParentNode.RemoveChild (elem)
Next
GetCodeWithSrcRacourci = "<html><head>" & styl & "</head>" & docHtml.body.outerHTML & "</html>"
End Function
Sub SendSelectionWithOutlook(cde, dossier, mode&)
Dim code$, I&, FichierHTML$, DossierImages$, nom$, Rng As Range, Q, tim#
Dim ob As Object, Adresse, OL As Object, OLmail As Object
tim = Timer
Set OL = CreateObject("Outlook.Application")
Set OLmail = OL.CreateItem(0) '0
With OLmail
'.From = CStr("guillaumepothier@hotmail.com")
.To = "dudu@youmémélle.com"
'.BodyFormat = olFormatHTML
.Subject = "plage+shape" & Date
.BodyFormat = 2
If mode = 2 Then
Q = Dir(dossier & "\*.png")
If Q <> "" Then
Do While Q <> ""
OLmail.Attachments.Add dossier & "\" & Q, 0, 0 ' les image sont invisibles dans les pieces jointes
OLmail.Attachments.Add dossier & "\" & Q ' on les rattache une 2d fois si on veut qu'elles soient visibles et télechargeables
Q = Dir
Loop
End If
End If
.HTMLBody = "bonjour salut<br>ci-joint le tableau des ventes du mois<br>" & cde & "<br>en vous souhaitant bonne reception<br>patrick à votre service"
.display
'.Save
'.Send 'envoi automatique
End With
CommandBars("Cell").Reset
CommandBars("List Range Popup").Reset
MsgBox Format(Timer - tim, "#0.000 Sec")
End Sub