VBA Taille incorrecte d'un fichier zippé attaché sur Outlook
Bonjour,
J'ai WinRar installé sur mon pc et quand je zippe le fichier Excel avec cette macro et je l'attache à mon email je trouve qu'il a une taille de 22 o au lieu de la taille de compression qui est de520 ko.
Le nom du fichier attaché est : Fichier test.zip (22o)
Sub Compresser_Fichier
Dim Chemin As String
Chemin = "C:\Moi\Mes documents\2021\"
' Compresser le fichier Xlsx en Zip
Dim oShell As Object, Fso As Object
Dim i As Long
Dim Fichier As String, MyBinary As String
Dim LeZip As Variant
Dim MyHex As Variant
Fichier = Chemin & "Fichier test.xlsx"
LeZip = Chemin & "Fichier test.zip"
Set Fso = CreateObject("Scripting.FileSystemObject")
MyHex = _
Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
For i = 0 To UBound(MyHex)
MyBinary = MyBinary & Chr(MyHex(i))
Next
With Fso.CreateTextFile(LeZip, True)
.Write MyBinary
.Close
End With
Set oShell = CreateObject("Shell.Application")
oShell.Namespace(LeZip).CopyHere (Fichier)
Set oShell = Nothing
End SubFichier attaché sur mon email
Préparation de l'email
' Code
Dim Rng As Range, MyChart As Chart
Const cSujet = "Test blaaaaaaaaaaaa blaaaaaaaaaaaa blaaaaaaaaaaaa"
Const cIntroduction = "Bonjour,<br/><br/> blaaaaaaaaaaaa blaaaaaaaaaaaa blaaaaaaaaaaaa blaaaaaaaaaaaa blaaaaaaaaaaaa.<br/><br/>"
Const cSignature = "Ma Signature"
Const xEMailAddr = "test@test.com"
Const xEMailAddrCopy = ""
Const xEMailAddrHidden = ""
Temps = Format(Now, "dddd")
Dim xOutlook As Object
Dim xMailItem As Object
Set xOutlook = CreateObject("Outlook.Application")
Set xMailItem = xOutlook.CreateItem(0)
With xMailItem
.DeferredDeliveryTime = (Vendredi & " " & "15:00:00")
.To = xEMailAddr
.CC = xEMailAddrCopy
.BCC = xEMailAddrHidden
.HTMLBody = Hbody & cIntroduction & cSignature
.Subject = cSujet
.Attachments.Add Fichier ' Le fichier compressé en .zip avec le WinRar et qui n'est pas attaché avec sa bonne taille sur mon email via outlook.
.Display
End With
' CodeMerci par avance pour votre retour.
Bonjour,
à lire ce que fait cette macro, j'ai de sérieux doutes qu'elle compresse ton fichier xlsx en fichier zip. Pour moi cette macro crée un fichier avec extension .zip qui contient 20 bytes dont les valeurs sont contenues dans myhex.
Bonjour h2so4,
C'est une macro que j'ai eu sur ce forum et je ne l'ai pas bien compris mais ça fonctionne puisque sur mon dossier "C:\Moi\Mes documents\2021\" je trouve le fichier zippé sous "Fichier test.zip"
Si tu as une autre avec grand plaisir pour la tester.