Hi! I have a few "problems" with VBA and excel/word so if someone can help me with this I will be very grateful. I get file with over 40 tables inside docx (word), mainly I am Desginer and need to transfer that tables inside Indesign but it's much easier to handle tables from excel rater than from word. So right now I acchive this.
Word VBA to extract all tables inside 1 word file, but i don't know how to add page break after each table.
And next thing is to read word file and import the tables inside the excel. Here I have a few questions, when I run this script I get the super clean file and I am ok with that, i just need to add that every table go on separate spreadsheet.
https://photos.app.goo.gl/YBmrakprxqyhwtgR7
From the image you can see on the left side the text that was manually input, but on the right side is directly from the excel, What I am missing on the right side is the enters. Is that possible to accomplished inside this script.
here is the code
thnx in advance
Word VBA to extract all tables inside 1 word file, but i don't know how to add page break after each table.
Code:
Sub ImportWordTable()Dim wdDoc As Object
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Word
Dim jRow 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
If wdDoc.tables.Count = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
Else
jRow = 0
Sheets.Add after:=Sheets(Worksheets.Count)
For TableNo = 1 To wdDoc.tables.Count
With .tables(TableNo)
'copy cell contents from Word table cells to Excel cells
For iRow = 1 To .Rows.Count
jRow = jRow + 1
For iCol = 1 To .Columns.Count
On Error Resume Next
ActiveSheet.Cells(jRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
On Error GoTo 0
Next iCol
Next iRow
End With
jRow = jRow + 1
Next TableNo
End If
End With
Set wdDoc = Nothing
End Sub
And next thing is to read word file and import the tables inside the excel. Here I have a few questions, when I run this script I get the super clean file and I am ok with that, i just need to add that every table go on separate spreadsheet.
https://photos.app.goo.gl/YBmrakprxqyhwtgR7
From the image you can see on the left side the text that was manually input, but on the right side is directly from the excel, What I am missing on the right side is the enters. Is that possible to accomplished inside this script.
here is the code
Code:
Sub ImportWordTable()Dim wdDoc As Object
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Word
Dim jRow 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
If wdDoc.tables.Count = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
Else
jRow = 0
Sheets.Add after:=Sheets(Worksheets.Count)
For TableNo = 1 To wdDoc.tables.Count
With .tables(TableNo)
'copy cell contents from Word table cells to Excel cells
For iRow = 1 To .Rows.Count
jRow = jRow + 1
For iCol = 1 To .Columns.Count
On Error Resume Next
ActiveSheet.Cells(jRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
On Error GoTo 0
Next iCol
Next iRowff
End With
jRow = jRow + 1
Next TableNo
End If
End With
Set wdDoc = Nothing
End Sub
thnx in advance