Carte du site
 Remerciements
 Netiquette
 Bugs
 Tables
 Requêtes
 Formulaires
 États (rapports)
 Modules
 APIs
 Chaînes
 Date/Time
 Général
 Ressources
 Téléchargeables

 Termes d'usage

General: Email ou exporter un graphique Chart depuis Access

Author(s)
Graeme Wilson

Email ou exporter un graphique Chart depuis Access.

    Parfois, il est nécessaire d'envoyer par email un Microsoft Graph 97 Chart depuis Access. Pour exporter ce graphique, utiliser la méthode Export de l'objet OleGraph object.

    Télécharger chartex.zip

Pour exporter le graphique comme une image JPG, vous pouvez utiliser le code qui suit:

'******** Code Start *********
Private Sub cmdExportGraph_Click()
  '=============================================
  '     Purpose: Export Graph
  '      E-Mail: Graeme.Wilson@nationsbank.co.uk
  '  Programmer: Graeme Wilson
  '=============================================
On Error GoTo cmdExportGraph_Click_Err
    Dim strErrMsg As String 'For Error Handling
    Dim oleGrf As Object
    Dim strFileName As String
    Dim strFilter As String
    Dim lngFlags As Long
    
    Set oleGrf = Me.OLEchart.Object
    
    strFileName = ahtCommonFileOpenSave(Flags:=lngFlags, InitialDir:="C:\", _
        Filter:="JPEG Files (*.jpg)", FilterIndex:=1, DefaultExt:="jpg", FileName:="MyGraph", _
        DialogTitle:="Save the Graph", OpenFile:=False)

oleGrf.Export FileName:=strFileName
MsgBox vbCrLf & "The Chart " & strFileName & " has been exported", _
        vbInformation + vbOKOnly, "Chart Exported :"

cmdExportGraph_Click_Exit:
Set oleGrf = Nothing
    Exit Sub

cmdExportGraph_Click_Err:
    Select Case Err
        Case 1004   ' Export Cancelled
            Resume cmdExportGraph_Click_Exit
        Case Else
            strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number) & vbCrLf & vbCrLf
            strErrMsg = strErrMsg & "Error Description: " & Err.Description & vbCrLf
            MsgBox strErrMsg, vbInformation, "cmdExportGraph_Click"
            Resume cmdExportGraph_Click_Exit
    End Select

End Sub
'********* Code End ***********

Alors que pour l'envoyer via Outlook en tant client pour votre courriel:

'********* Code start ***********

Private Sub cmdEmailGraph_Click()
  '=============================================
  '     Purpose: E-Mail Graph
  '      E-Mail: Graeme.Wilson@nationsbank.co.uk
  '  Programmer: Graeme Wilson
  '=============================================
On Error GoTo cmdEmailGraph_Click_Err
    Dim strErrMsg As String 'For Error Handling
    Dim olApp As New Outlook.Application
    Dim olNameSpace As Outlook.NameSpace
    Dim olMail As Outlook.MailItem
    Dim oleGrf As Object
    Dim strFileName As String
    
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olMail = olApp.CreateItem(olMailItem)
Set oleGrf = Me.OLEchart.Object
strFileName = "c:\temp\Graph.jpg"
oleGrf.Export FileName:=strFileName

With olMail
    .To = "Graeme.Wilson@nationsbank.co.uk"
    .Subject = "Graph Info " & Format(Now(), "dd mmm yyyy  hh:mm")
    .Attachments.Add strFileName
    .ReadReceiptRequested = False
    .Send
End With
Kill strFileName

MsgBox vbCrLf & "Chart has been E-Mailed", _
        vbInformation + vbOKOnly, "Chart Exported :"


cmdEmailGraph_Click_Exit:
Set olApp = Nothing
Set olMail = Nothing
Set oleGrf = Nothing
    Exit Sub

cmdEmailGraph_Click_Err:
    Select Case Err
        Case Else
            strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number) & vbCrLf & vbCrLf
            strErrMsg = strErrMsg & "Error Description: " & Err.Description & vbCrLf
            MsgBox strErrMsg, vbInformation, "cmdEmailGraph_Click"
            Resume cmdEmailGraph_Click_Exit
    End Select

End Sub
'************ Code End *************
  • © 1998-2001, Dev Ashish, All rights reserved. Optimized for Microsoft Internet Explorer