R
Rob
Hi,
I am completely new to Word programming, so I am not even sure if this
is the way to solve my problem, but here goes:
I have approximately 400-500 HTML tables in various HTML files (the
data making up these tables also exists in tab delimited ASCII files).
My goal is to insert the tables into a Word document.
The problems I am facing are:
1.) How do I "loop" over each HTML file & "grab" the table & insert
it into the appropriate place within the Word document? I can do this
manually by going to "Insert" then "file" then navigating to the
proper file & inserting it into Word, then manually moving my cursor
to the next place within Word and doing it again. However, because
there are, as I said, hundreds of tables, this obviously will not
work. I recorded a simple macro as a "proof of concept" to ensure I
could do what I wanted, but it needs to be a lot more robust:
Dim pCell1 As Word.Cell
Dim pCell2 As Word.Cell
Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table)
'Copies tables cell for cell left to right
Dim pCell1 As Word.Cell
Dim pCell2 As Word.Cell
Set pCell1 = pTable1.Cell(1, 1)
Set pCell2 = pTable2.Cell(1, 1)
Do
pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2)
Set pCell1 = pCell1.Next
Set pCell2 = pCell2.Next
Loop Until pCell1 Is Nothing
End Sub
Sub Insert_Table()
'
' Insert_Table Macro
' Macro recorded 12/1/2009 by Robert Paul Brookover III
'
ChangeFileOpenDirectory _
"D:\data\<user>\Desktop\macro_examples\Table_Macro\"
Selection.InsertFile FileName:="Table_Example.htm", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.MoveDown Unit:=wdLine, Count:=6
Selection.InsertFile FileName:="Table_Example2.htm", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub
2.) What I need help on are modifying the macro to place the tables
into specific places within Word - what is the best way to "prepare"
Word to accept table data in specific places? Do I use bookmarks, or
what?
The person providing the tables said that he could make "one huge"
HTML file and I could just import that into Word, but then the problem
would be how to correctly set up the captions within Word to say
"Table XX-X blah" and "Table XX-Y blah"
Another option is to insert the tab delimited files and have Word
convert them to Word tables. Whichever is easier, it doesn't matter
to me.
Thanks in advance,
Rob
I am completely new to Word programming, so I am not even sure if this
is the way to solve my problem, but here goes:
I have approximately 400-500 HTML tables in various HTML files (the
data making up these tables also exists in tab delimited ASCII files).
My goal is to insert the tables into a Word document.
The problems I am facing are:
1.) How do I "loop" over each HTML file & "grab" the table & insert
it into the appropriate place within the Word document? I can do this
manually by going to "Insert" then "file" then navigating to the
proper file & inserting it into Word, then manually moving my cursor
to the next place within Word and doing it again. However, because
there are, as I said, hundreds of tables, this obviously will not
work. I recorded a simple macro as a "proof of concept" to ensure I
could do what I wanted, but it needs to be a lot more robust:
Dim pCell1 As Word.Cell
Dim pCell2 As Word.Cell
Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table)
'Copies tables cell for cell left to right
Dim pCell1 As Word.Cell
Dim pCell2 As Word.Cell
Set pCell1 = pTable1.Cell(1, 1)
Set pCell2 = pTable2.Cell(1, 1)
Do
pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2)
Set pCell1 = pCell1.Next
Set pCell2 = pCell2.Next
Loop Until pCell1 Is Nothing
End Sub
Sub Insert_Table()
'
' Insert_Table Macro
' Macro recorded 12/1/2009 by Robert Paul Brookover III
'
ChangeFileOpenDirectory _
"D:\data\<user>\Desktop\macro_examples\Table_Macro\"
Selection.InsertFile FileName:="Table_Example.htm", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.MoveDown Unit:=wdLine, Count:=6
Selection.InsertFile FileName:="Table_Example2.htm", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub
2.) What I need help on are modifying the macro to place the tables
into specific places within Word - what is the best way to "prepare"
Word to accept table data in specific places? Do I use bookmarks, or
what?
The person providing the tables said that he could make "one huge"
HTML file and I could just import that into Word, but then the problem
would be how to correctly set up the captions within Word to say
"Table XX-X blah" and "Table XX-Y blah"
Another option is to insert the tab delimited files and have Word
convert them to Word tables. Whichever is easier, it doesn't matter
to me.
Thanks in advance,
Rob