Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$old_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ext-thumbnail_url is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
Esportare la posta elettronica da Outlook ad Access | IlSoftware.it

Esportare la posta elettronica da Outlook ad Access

In molti contesti lavorativi può risultare necessario esportare le e-mail gestite con Microsoft Outlook all'interno di un database Access.

In molti contesti lavorativi può risultare necessario esportare le e-mail gestite con Microsoft Outlook all’interno di un database Access. La procedura passo-passo integrata nel client di posta Outlook è semplice ed efficace ma ha un grosso limite: non è possibile aggiungere dati ad un database creato in precedenza. Se si desidera esportare frequentemente i dati nel medesimo database, è possibile applicare una soluzione basata sull’uso di codice VBA (Visual Basic for Applications).
Per esportare l’archivio di posta usando la procedura offerta da Outlook, è sufficiente fare riferimento all’apposito “wizard”, accessibile facendo riferiemento alla funzione Importa/Esporta del menù File. Si dovrà semplicemente scegliere l’esportazione dei dati in formato Access, selezionare la cartella desiderata e premere il pulsante “Avanti”.

Utilizzando del codice VBA, l’utente ha la possibilità di automatizzare l’intera procedura di esportazione da Outlook verso una base dati Access: premendo la combinazione di tasti ALT+F11 da Microsoft Outlook si avrà accesso all’Editor Visual Basic (VBE). Dal menù Inserisci, va selezionata la voce “Modulo” quindi si può procedere all’inserimento del seguente codice:

Sub EsportaPosta()
    Dim ns As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Set ns = GetNamespace("MAPI")
    Set objFolder = ns.PickFolder
    Dim adoConn As ADODB.Connection
    Dim adoRS As ADODB.Recordset
    Dim intCounter As Integer
    Set adoConn = CreateObject("ADODB.Connection")
    Set adoRS = CreateObject("ADODB.Recordset")
    adoConn.Open "DSN=DatiOutlook;"
    adoRS.Open "SELECT * FROM email", adoConn, adOpenDynamic, adLockOptimistic
    For intCounter = objFolder.Items.Count To 1 Step -1
        With objFolder.Items(intCounter)
            if .Class = olMail Then
            adoRS.AddNew adoRS("Subject") = .Subject
            adoRS("Body") = .Body
            adoRS("FromName") = .SenderName
            adoRS("ToName") = .To
            adoRS("FromAddress") = .SenderEmailAddress
            adoRS("FromType") = .SenderEmailType
            adoRS("CCName") = .CC
            adoRS("BCCName") = .BCC
            adoRS("Importance") = .Importance
            adoRS("Sensitivity") = .Sensitivity
            adoRS.Update
            End If
        End With
    Next
    adoRS.Close
    Set adoRS = Nothing
    Set adoConn = Nothing
    Set ns = Nothing
    Set objFolder = Nothing
End Sub

Prima di eseguire la macro appena creata, è indispensabile – in questo caso – creare il database Access sul quale si andrà a memorizzare i dati esportati da Outlook. E’ possibile, a tal proposito, servirsi di quello che può essere creato sfruttando la procedura passo-passo integrata in Outlook. Si può comunque impiegare, come base dati per la memorizzazione delle e-mail esportate da Outlook, anche un database già esistente: è sufficiente creare una tabella denominata “email” con i vari campi richiesti (Subject, Body, FromName, ToName, FromAddress,…). Tutti i campi sono di tipo testo tranne “Body” che deve essere necessariamente impostato come campo “memo”.
I nomi dei campi ricalcano quelli impiegati dal wizard di Outlook purtuttavia possono essere liberamente modificati.
Il codice utilizza una connessione DSN (driver ODBC) per “dialogare” con la base dati Access. E’ comunque possibile utilizzare altre stringhe di connessione. Se si usa una connessione DSN, è necessario accedere alla finestra “Strumenti di amministrazione” di Windows quindi fare doppio clic sull’icona “Origine dati (ODBC)”. Nella finestra “DNS utente” è necessario selezionare “MS Access Database” quindi cliccare su “Aggiungi”. Nella schermata successiva, va scelto “Microsoft Access Driver (*.mdb)” quindi cliccare sul pulsante “Fine”.
Nella finestra “Configurazione ODBC per Microsoft Access”, attribuire al DSN il nome “DatiOutlook”. Cliccando il pulsante “Seleziona”, si dovrà indicare il database Access da utilizzare.

Dopo aver creato il DSN, si potrà eseguire la macro da Outlook accedendo al menù Strumenti, Macro. A questo punto, si deve selezionare la macro “EsportaPosta” e premere il pulsante Esegui.

Ti consigliamo anche

Link copiato negli appunti