1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| Dim oTbl As TableDef
For Each oTbl In CurrentDb.TableDefs
If oTbl.Attributes = 0 Then ' Exporte seulement les tables de la base
DoCmd.TransferDatabase acExport, "Microsoft Access", "D:\sauve_base\base.mdb", acTable, oTbl.Name, oTbl.Name
End If
Next
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 = "D:\sauve_base\base.mdb"
LeZip = "D:\sauve_base\base.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)
'envoi du mail
'on déclare les variables de l'objet Outlook
Dim MonOutlook As Object
Dim MonMessage As Object
Set MonOutlook = CreateObject("Outlook.Application")
Set MonMessage = MonOutlook.createitem(0)
'on déclare les champs de l'e-mail (de, à, cc, cci, objet, contenu)
MonMessage.To = "moi@moi.fr"
MonMessage.Subject = "sauvegarde"
MonMessage.body = "Voici la sauvegarde"
monfichier = LeZip
MonMessage.Attachments.Add monfichier
MonMessage.send
' on libère toutes les variables déclarées...
' Un petit message de confirmation
MsgBox "Opération terminée !", vbInformation, "xxxxxxxxxxxx"
Set MonOutlook = Nothing
Set MonMessage = Nothing
Set Fso = Nothing
Set oShell = Nothing
End Sub |
Partager