Vb Script to read table from Word RRS feed

  • Question

  • Hello all,

    Currently am developing a macro to compare a column in excel with the column of a table in word document. Word document i use has nearly 100 tables, i need to filter out the table with the specific keyword and copy the content to excel for further steps.

    Now i have developed code to get the table from word with the help of table number. But the table number has to be given input by the user. i need read the table without giving any other input by user.

    Thanks in advance.. Awaiting for your feedback..!

    Monday, June 13, 2016 4:27 AM


All replies

  • Can you post your Word / Excel document with the code here?

    Best regards, George

    Monday, June 13, 2016 11:49 AM
  • Dim wdDoc As Object
    Dim wdFileName As Variant
    Dim TableNo As Integer 'table number in Word
    Dim iRow As Long 'row index in Excel
    Dim iCol As Integer 'column index in Excel

    wdFileName = Application.GetOpenFilename("Word files (*.doc),*.doc", , _
    "Browse for file containing table to be imported")

    If wdFileName = False Then Exit Sub '(user cancelled import file browser)

    Set wdDoc = GetObject(wdFileName) 'open Word file

    With wdDoc
        TableNo = wdDoc.tables.Count
        If TableNo = 0 Then
            MsgBox "This document contains no tables", _
            vbExclamation, "Import Word Table"
        ElseIf TableNo > 1 Then
            TableNo = InputBox("This Word document contains " & TableNo & " tables." & vbCrLf & _
            "Enter table number of table to import", "Import Word Table", "1")
        End If
    Monday, June 13, 2016 1:14 PM
  • Dim I as integer


    With wdDoc
        TableNo = wdDoc.tables.Count
    For I = 1 to TableNo

    ' ... Your code here ...

    Next I

    End With

    Best regards, George

    Monday, June 13, 2016 1:32 PM
  • Hi KVignesh,

    please check the suggestion given by the George.B.Summers.

    I think the suggestion given by him can solve your issue.

    it will loop all your tables till last one.

    if you think it can solved your issue then I would recommend you to mark the suggestion given by him as an Answer.

    if you still having a problem regarding that please let us know so that we can provide you further help.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 14, 2016 12:22 AM