Hello
I would like to ask you, I tried to search in Google but i have find this code and change name of file and sheet. But not function, I think that I have to write the error of code?
Sorry I am not very expert of VBA and I am studying.
Const xlUp As Long = -4162
Sub ExportToExcel(MyMail As MailItem)
Dim strID As String, olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim StrBody As String
Dim strFileName As String
'~~> Excel Variables
Dim oXLApp As Object, oXLwb As Object, oXLws As Object
Dim lRow As Long
strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
'~~> Establish an EXCEL application object
On Error Resume Next
Set oXLApp = GetObject(, "Excel.Application")
'~~> If not found then create new instance
If Err.Number <> 0 Then
Set oXLApp = CreateObject("Excel.Application")
End If
Err.Clear
On Error GoTo 0
'~~> Show Excel
oXLApp.Visible = True
'~~> Open the relevant file
Set oXLwb = oXLApp.Workbooks.Open("D:\Profili\xxxxxx\Desktop\xxxxx.xlsm")
'~~> Set the relevant output sheet. Change as applicable
Set oXLws = oXLwb.Sheets("AAAAAA")
lRow = oXLws.Range("A" & oXLApp.Rows.Count).End(xlUp).row + 1
'~~> Write to outlook
With oXLws
'
'~~> Code here to output data from email to Excel File
'~~> For example
.Range("A" & lRow).Value = olMail.Subject
.Range("B" & lRow).Value = olMail.SenderName
.Range("C" & lRow).Value = olMail.ReceivedTime
.Range("D" & lRow).Value = olMail.HtmlBody
olMail.HtmlBody = StrBody
"<td style="padding-right: 7px; padding-left: 7px;"> 12/09/2015 12:30:00</td>"&
"<td style="padding-right: 7px; padding-left: 7px;">Court</td>"& _
"<td style="padding-right: 7px; padding-left: 7px;">Number</td>"& _
"<td style="padding-right: 7px; padding-left: 7px;">Players</td>"& _
"<td style="padding-right: 7px; padding-left: 7px;">Name</td>"& _
"<td style="padding-right: 7px; padding-left: 7px;">Fullname</td>"& _
"<td id="yui_3_16_0_1_1442210929051_2289" style="padding-right: 7px; padding-left: 7px;">Age</td>"& _
"<td style="padding-right: 7px; padding-left: 7px;">Country</td>"& _
"<td style="padding-right: 7px; padding-left: 7px;">Time</td>"& _
End With
'~~> Close and Clean up Excel
oXLwb.Close (True)
oXLApp.Quit
Set oXLws = Nothing
Set oXLwb = Nothing
Set oXLApp = Nothing
Set olMail = Nothing
Set olNS = Nothing
End Sub
Give me the error :-(
I hope that you will help me to solve it.
Thanks.
Davide
Bookmarks