VBA: extract 2nd column data of word table to excel

Status
Not open for further replies.

Xlacs

Board Regular
Joined
Mar 31, 2021
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hello,

So I managed to identify all the word docs in a particular folder. However, I'm having a problem achieving to extract the 2nd column row 2 data of the table of all word docx.

Error: Set Table = doc.Table
" Object variable block"

The word table looks like the attached img. I only wanted to extract the "x" starting from row 2 column 2..

Hoping someone can actually help me on this.. Thank you in Advance!

QuestionsAgreeDisagreeNeutral
What is...x
What is..x


VBA Code:
Sub Open_Multiple_Word_Files(sPattern As String)
Dim shApp As Object
Dim shFolder As Object
Dim File, Files
Dim currentPath As String
Dim doc As Word.Document
Dim wd As New Word.Application
Dim sh As Worksheet


'get folder
    Set shApp = CreateObject("shell.application")
    folder2search = "C:\Users\ChrisLacs\Desktop\extrac\"
    Set shFolder = shApp.Namespace(folder2search)
'get files
    Set Files = shFolder.Items()
'check if file names match the pattern
    For Each File In Files
        If File.Name Like sPattern Then
        
        
           

Set Table = doc.Table
Set sh = ActiveSheet

lr = sh.Cells(Rows.Count, 1).End(xlUp).Row + 1

For i = 1 To 6
    sh.Cells(lr, i).Value = Application.WorksheetFunction.Clean(Table(1).Rows(i).Cells(2).Range.Text)
    
            
            Debug.Print File.Name & " - " & (File.Name Like sPattern)
            Next
        End If
    Next File
End Sub

Sub Search_it()
    Open_Multiple_Word_Files "Form*"
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Duplicate to: VBA: Extract specific word table to excel

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top