Add Text Above MSWord Table Using VBS

微笑、不失礼 提交于 2019-12-25 14:30:01

问题


I am working on creating a signature in outlook using VBS to push to our users. The signature has tables in it so i can have a logo / user information side by side vs. the standard text on top of a logo. (Original table code found here: http://www.vbforums.com/showthread.php?526706-resolved-question-with-tables-in-vbscript-for-AD-signature)

Below is a snipit of the code that writes to the doc file. The code sucessfully creates two coluns and puts whatever information i want into them. Is there a way to add text to the top of the doc file before it starts creating / editing the tables?

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:


I stumbled upon the issue by working with the script found here: 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)


来源:https://stackoverflow.com/questions/13032677/add-text-above-msword-table-using-vbs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!