PDA

View Full Version : Converting worksheets to Word tables



JoA
01-07-2008, 07:18 AM
The purpose of this macro is to loop through all Excel worksheets pasted into the Word document. Copy the worksheet, delete the worksheet and then paste the worksheet back into the document as a Word table.

I would like to make the whole process invisible to the user.
Also some of the tables are very large so screen updating takes a lot of the resources, any suggestions?

My code looks like this:


Sub XLtoWordTables()

Dim ishape As InlineShape
Dim myObj As Object
Dim MyExcel As Object

For Each ishape In ActiveDocument.InlineShapes

If ishape.Type = wdInlineShapeEmbeddedOLEObject Then

If ishape.OLEFormat.ProgID >= "Excel.Sheet" Then

ishape.Select

ishape.OLEFormat.Activate
Set myObj = ishape.OLEFormat.Object

myObj.Application.Visible = False

Set MyExcel = myObj.Application

MyExcel.Visible = False

MyExcel.Selection.Copy

Set Myworksheet = Nothing
Set MyExcel = Nothing
Set myObj = Nothing

Selection.Paste
End If
End If
Next
End Sub