Hello everyone,
I have been assigned a task at work to write a VBA for automation. We have many word documents in a folder that have hundreds of tables within them. I want to create an automation program that is going to retrieve tables from the word document specified and go through the document table by table copying these tables into a separate Excel sheet named after the document itself. As I have never worked with VBA before I was able to get code that finds the tables in a word document but I want the program to create a loop that can copy these tables into a spreadsheet. So far I have this
Sub findTable()
Dim iResponse As Integer
Dim tTable As Table
' Dim ExcelSheet
' Set ExcelSheet = CreateObject("Excel.Application") trying to get an excel sheet open
' ExcelSheet.Visible = True
'If any tables exist, loop through each table in collection.
For Each tTable In ActiveDocument.Tables
tTable.Select
Selection.Copy
ExcelSheet.Workbooks.Open ActiveDocument.Path & Application.PathSeparator & "test.xls"
' ThisWorkbook.Activate
' Workbooks.Open "D:\Profiles\RIZWANHA\Desktop\FrameMaker files\test.xls"
Selection.Paste
'iResponse = MsgBox("Table found. Find next ", 68)
'If response = vbNo Then Exit For 'User chose to leave search.
Next
MsgBox prompt:="Search Complete.", buttons:=vbInformation
End Sub
I am getting errors when I try pasting into the excel spreadsheet. Your help will be appreciated.
Thanks