• Regolamento Macrocategoria DEV
    Prima di aprire un topic nella Macrocategoria DEV, è bene leggerne il suo regolamento. Sei un'azienda o un hosting/provider? Qui sono anche contenute informazioni per collaborare con Sciax2 ed ottenere l'accredito nella nostra community!

Domanda Esportazione email in excel

morpheus1976

Nuovo utente
Autore del topic
21 Marzo 2013
1
0
Miglior risposta
0
Ciao a tutti,
per prima cosa buongiorno a tutti, sono un nuovo utente e sono approdato su questo forum dopo aver girovagato per la rete, spero che qualcuno di voi esperto in materia possa risolvere il mio problema.

Ricevo mediamente 200 mail al giorno e ho la necessità di copiare alcuni campi di queste mail all'interno di un file excel, in modo da poter poi avere traccia e verificare gli sla dei ticket.

L'operazione oltre che essere monotona mi porta via tantissimo tempo e allora ho deciso di cercare in rete una soluzione, e guardando un po' in giro anche su forum americani ho visto la possibilità di creare delle macro in outlook che possono automatizzare il processo.

Ovviamente non avendo mai progettato in VB ho bisogno di qualcuno che possa dirmi che codice utilizzare, in rete ho trovato questo esempio:

Sub ParseEmailFolderToExcel()
Set objApp = Application
Dim olns As Outlook.NameSpace
Set olns = Outlook.GetNamespace("MAPI")
Set myinbox = olns.PickFolder
Dim XLApp As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim EachElement()
Dim myRecipient As Outlook.Recipient

Dim ExcelWasNotRunning As Boolean

On Error Resume Next
Set XLApp = GetObject(, "Excel.Application")

If Err Then
ExcelWasNotRunning = True
Set XLApp = New Excel.Application
XLApp.Visible = True
End If
On Error GoTo 0
Set wkb = XLApp.Workbooks.Add
Set wks = wkb.Sheets(1)
With wks
StartCount = 1 'how many emails (start at 1 to leave row one for headers)
strEmailContents = ""
For Each outlookmessage In myinbox.Items
StartCount = StartCount + 1 'increment email count
.Range("A" & StartCount).Value = outlookmessage.ReceivedTime
.Range("B" & StartCount).Value = outlookmessage.SenderName
.Range("C" & StartCount).Value = outlookmessage.Subject
.Range("D" & StartCount).Value = Right(outlookmessage.SenderEmailAddress, 5)

Set myRecipient = olns.CreateRecipient(Right(outlookmessage.SenderEmailAddress, 5))
myRecipient.Resolve
If myRecipient.Resolved Then
Debug.Print myRecipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress
End If

UseCol = 1 'E; previous columns hold the email header information shown above (sender, date, etc)

FullMsg = outlookmessage.Body
AllLines = Split(FullMsg, vbCrLf)

For FullLine = LBound(AllLines) To UBound(AllLines)
On Error Resume Next
'Here is where you could decide to process only certain lines, using maybe a select case statement

eachVal = Split(AllLines(FullLine), ",") 'for a comma delimited file
For EachDataPoint = LBound(eachVal) To UBound(eachVal) 'load each value to an array
UseCol = UseCol + 1
ReDim Preserve EachElement(UseCol)
'.cells(row,column)
EachElement(UseCol - 1) = eachVal(EachDataPoint)
'.Cells(StartCount, UseCol - 1).Value = eachVal(EachDataPoint)
Next
Next
On Error GoTo 0


Questo in parte lanciando la macro mi genera un file excel e mi inserisce 4 o 5 dei campi che a me invece servirebbero.

Potreste aiutarmi?
Vi servono le mail che ricevo e come dovrebbe essere strutturato il file?
Grazie per chi mi aiuterà è molto importante