View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone[_2_] Jim Cone[_2_] is offline
external usenet poster
 
Posts: 1,549
Default Import Word Table Macro running very slow

Try this one...
'---
Sub ImportDoc_R3()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdTable As Word.Table
Dim wdRow As Word.Row
Dim wdCell As Word.Cell
Dim nRow As Long
Dim nCol As Long
Dim bHeader As Boolean

Application.ScreenUpdating = False
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open(Filename:="C:\Test.doc")
With ActiveSheet.Range("A1:E999")
.Clear
.NumberFormat = "dd/mm/yyyy"
End With
nRow = 1

For Each wdTable In wdDoc.Tables
bHeader = True
For Each wdRow In wdTable.Rows
nCol = 1
nRow = nRow + 1
For Each wdCell In wdRow.Cells
nCol = nCol + 1
With ActiveSheet.Cells(nRow, nCol)
.Font.Bold = bHeader
If bHeader Then .HorizontalAlignment = xlCenter
wdCell.Range.Copy
.PasteSpecial xlPasteValues
End With
Next
bHeader = False
Next
nRow = nRow + 1
Next

Set wdTable = Nothing
Set wdRow = Nothing
Set wdCell = Nothing
wdDoc.Close SaveChanges:=0
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
Application.ScreenUpdating = True
End Sub
'---




"prkhan56"
wrote in message
Hi Jim
I cant run this macro.
I can't even see it under the Macro Name
I think it has to with the line:
Sub ImportDoc_R2(Optional ByRef bHeader As Boolean = True)

Kindly guide me
Thanks