Jeg forsøge at kopiere flere tabeller fra et worddokument over i et excel, hvortil jeg har fundet en rigtig god vba på nettet (se nedenstående). Jeg har meget lidt erfaring med vba og vil derfor høre, om nedenstående kan redigeres, så den OGSÅ kan:
-
kopiere "merged" tabeler
- kopiere "numeriske tal"
Sub ImportWordTable()
On Error GoTo errHandler
Dim wordDoc As Object
Dim wdFileName As Variant
Dim noTble As Integer
Dim rowNb As Long
Dim colNb As Integer
Dim x As Long, y As Long
x = 1: y = 1
wdFileName = Application.GetOpenFilename("Word files (*.doc),*.doc", , _
"Browse for file containing table to be imported") 'adjust this to the document type you are after
If wdFileName = False Then Exit Sub
Set wordDoc = GetObject(wdFileName)
With wordDoc
noTble = wordDoc.tables.Count
If noTble = 0 Then
MsgBox "No Tables in this document", vbExclamation, "No Tables to Import"
Exit Sub
End If
For k = 1 To noTble
With .tables(k)
For rowNb = 1 To .Rows.Count
For colNb = 1 To .Columns.Count
Cells(x, y) = WorksheetFunction.Clean(.cell(rowNb, colNb).Range.Text)
y = y + 1
Next colNb
y = 1
x = x + 1
Next rowNb
End With
x = x + 2
Next
End With
Set wordDoc = Nothing
Exit Sub
errHandler:
MsgBox "Error in generating tables - " & Err.Number & " - " & Err.Description
End Sub