VBScript生成Word,并添加表格及书签

2010-09-19 13:44:57来源:西部e网作者:

'/*=========================================================================
' * Intro       VBScript生成Word,并添加表格及书签
' * FileName    VBScript-Word-Table-Bookmarks.vbs
' * Author      yo

'/*=========================================================================
' * Intro       VBScript生成Word,并添加表格及书签
' * FileName    VBScript-Word-Table-Bookmarks.vbs
' * Author      yongfa365
' * Version     v1.0
' * WEB         http://www.yongfa365.com
' * Email       yongfa365[at]qq.com
' * FirstWrite  http://www.yongfa365.com/Item/VBScript-Word-Table-Bookmarks.vbs.html
' * MadeTime    2008-10-18 22:15:40
' * LastModify  2008-10-18 22:15:40
' *==========================================================================*/

Set objWord = CreateObject("Word.Application")

objWord.Visible = True
'Set objDoc = objWord.Documents.Open("http://www.yongfa365.com/Test.doc")
'Set objDoc = objWord.Documents.Open("C:\Test.doc")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
'在Word里添加一个二行四列的表格
Set table1 = objSelection.Tables.Add(objSelection.Range, 2, 4)

'Set Table1 = objDoc.Tables(1)
rowcount = Table1.Rows.Count
For i = 1 To Table1.Rows.Count
    For j = 1 To Table1.Columns.Count
        '在单元格i,j里填充内容
        Table1.Cell(i, j).Range.Text = "第" & i & "行" & j & "列"
        '为单元格i,j添加书签
        Table1.Cell(i, j).Range.Bookmarks.Add "书签" & i & "行," & j & "列"
    Next
Next

原文地址:http://www.yongfa365.com/item/VBScript-Word-Table-Bookmarks.vbs.html
关键词:VBScript