Copy tables from outlook to excel

jpo1976

New Member
Joined
Jan 25, 2018
Messages
1
I receive everyday reports with tables in outlook, I want to create a macro that can copy the table in a new excel file and save it to a folder in my desktop, I have this code that it is working with small tables, 100 or 200 rows, but it fails with bigger tables with 2000 rows or more, the error is this:

Run-time error '-2147417848 (80010108)
Method 'Copy' of object 'Range' failed

but if I run the macro with the email open it works with the big tables, so I think the problem is maybe with the time that takes to copy the tables, but dont know what to do, can someone give me a suggestion please?

Sub test5()


Dim item As MailItem, x%
Dim r As Object 'As Excel.Range
Dim doc As Object 'As Excel.Document
Dim xlApp As Object, wkb As Object
Dim FTW As String


For Each item In Application.ActiveExplorer.Selection
Set xlApp = CreateObject("Excel.Application")
Set wkb = xlApp.Workbooks.Add
xlApp.Visible = True


Dim wks As Object
Set wks = wkb.Sheets(1)
Set doc = item.GetInspector.WordEditor
For x = 1 To doc.tables.Count
Set r = doc.tables(1)
doc.tables(1).Range.Copy
wks.Paste
wks.Cells(wks.Rows.Count, 1).End(3).Offset(1).Select
FTW = wks.Cells(1, 1)
FTW = Replace(FTW, ":", " ")


wkb.SaveAs filename:="C:\temp" & FTW & Format(item.CreationTime, "yyyymmdd_hhnnss_") & ".xlsx"
wkb.Close
Next


Next


End Sub


PS: I am not a programmer and dont know about VBA, I was just reading other forums and trying to adapt the code, so I am not sure if this is the best option.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,213,487
Messages
6,113,943
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top