Dansk Regneark Forum
  Hjælp Hjælp  Søg i forum   Arrangementer   Opret ny bruger Opret ny bruger  Log ind Log ind


Emne lukketTabel fra word til excel

 Besvar Besvar
Forfatter
krich Se dropdown
Forum Begynder
Forum Begynder


Medlem: 10.Mar.2014
Land: dk
Status: Offline
Point: 1
Direkte link til dette indlæg Emne: Tabel fra word til excel
    Sendt: 10.Mar.2014 kl. 15:57

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

Til top



Til top
 Besvar Besvar

Skift forum Forum tilladelser Se dropdown

© 2010 - 2024 Dansk Regneark Forum - en del af Excel-regneark.dk