Dim wordApp As New WordApplication()
Dim myDoc As WordDocument
Dim oTable As WordTable
Dim rowIndex colIndex As Integer
rowIndex =
colIndex =
wordAppDocumentsAdd()
myDoc = wordAppActiveDocument
Dim Table As New DataTable()
Table = CreaTable()
oTable = myDocTablesAdd(Range:=myDocRange(Start:= End:=) NumRows:=TableRowsCount + NumColumns:=TableColumnsCount)
将所得到的表的列名赋值给单元格
Dim Col As DataColumn
Dim Row As DataRow
For Each Col In TableColumns
colIndex = colIndex +
oTableCell( colIndex)RangeInsertAfter(ColColumnName)
Next
得到的表所有行赋值给单元格
For Each Row In TableRows
rowIndex = rowIndex +
colIndex =
For Each Col In TableColumns
colIndex = colIndex +
oTableCell(rowIndex colIndex)RangeInsertAfter(Row(ColColumnName))
Next
Next
oTableBordersInsideLineStyle =
oTableBordersOutsideLineStyle =
wordAppVisible = True
总结Microsoft Word (版本号)对象库提供了Word的大部分操作类似的也有Microsoft Excel 对象库我们可以用代码与Word和Excel进行会话并控制它们还有很重要的一点就是我们必须学会使用OFFICE软件的宏宏是一系列的Word(或其它OFFICE软件)命令和指令的组合都是生成VB代码我们可用工具/宏/录制新宏来录制宏录制完成后查看宏的代码就可以知道实现此功能的一系列的VB代码我们把这些代码拷贝到VBnet编辑器中稍微改动后就可以使用要想做好OFFICE开发必须用好VBA和宏
[] []