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和宏
[] []
From:http://tw.wingwit.com/Article/program/net/201311/15544.html