使用VBS在MSWord表上方添加文本

时间:2012-10-23 14:25:26

标签: vbscript ms-word word-2010

我正在使用VBS在outlook中创建签名以推送给我们的用户。签名中有表格,因此我可以将徽标/用户信息与徽标顶部的标准文本并排放置。 (原始表格代码见http://www.vbforums.com/showthread.php?526706-resolved-question-with-tables-in-vbscript-for-AD-signature

下面是写入doc文件的代码片段。代码成功地创建了两个coluns并将我想要的任何信息放入其中。有没有办法在开始创建/编辑表之前将文本添加到doc文件的顶部?

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.Style = "No Spacing"
Set objRange = objDoc.Range()
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries


'I want to add text here above the two tables below.  Not sure how to do it.


'Create Tables
objDoc.Tables.Add objRange, 1, 2
Set objTable = objDoc.Tables(1)

'** Logo table **
objTable.Cell(1, 1).select
'Put Logo information here

'** User table **
objTable.Cell(1, 2).select
'Put User information here

objSelection.EndKey 6  'Command to end the above tables

1 个答案:

答案 0 :(得分:0)

我通过使用此处找到的脚本偶然发现了这个问题:http://blogs.technet.com/b/heyscriptingguy/archive/2006/06/09/how-can-i-add-multiple-tables-to-a-word-document.aspx

'Create Tables
Set objRange = objSelection.Range 'Adding this line fixed the problem
objDoc.Tables.Add objRange, 1, 2
Set objTable = objDoc.Tables(1)