Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate a Word table from an InfoPath form using VBScript 2

Status
Not open for further replies.

migv1

Technical User
Apr 23, 2004
39
0
0
US
I posted this last week in Google Groups microsoft.public.infopath last week and got no takers. Maybe someone here can help?

Does anyone know how to populate a Word table with data from an InfoPath form using VBScript?
I've already figured out how to open the Word template and transfer data from single XML nodes to bookmarked locations:

Set Title = XDocument.DOM.selectSingleNode("//my:Title")
strTitle = Title.Text

Set Author = XDocument.DOM.selectSingleNode("//my:Author")
strAuthor = Author.Text

Set objWord = CreateObject("Word.Application")
objWord.Visible = True

Set objDoc = objWord.Documents.Open("C:\Test\Template.doc")

Set objRange = objDoc.Bookmarks("Title").Range
objRange.Text = strTitle

Set objRange = objDoc.Bookmarks("Author").Range
objRange.Text = strAuthor

<and so on...>

This works fine, but I'm stumped on how to transfer data in tables.

If someone could tell me the equivalent in VBScript of the following VBA code (to run when a button is clicked in InfoPath), I think I can make this work:

With Selection
.GoTo What:=wdGoToBookmark, Name:="TestTable"
.TypeText Text:="1"
.MoveRight Unit:=wdCell
.TypeText Text:="3F"

>and so on...>

End With

Thanks in advance for any help or suggestions.
 
The general approach is to read the document which specifies positional version. Use only positional variables. And then declare all the built-in constants used or take them as some sort of magic number.
[tt]
With Selection
.GoTo -1,,,"TestTable" 'wdGoToBookmark=-1 (&HFFFFFFFF)
.TypeText "1"
.MoveRight 12 'wdCell=12; default count=1
.TypeText "3F"
'and so on...>
End With
[/tt]
 
Hi, tsuji:

Forgive my ignorance, but what would be the VBScript equivalent of the With Selection... code? That code was taken from Word VBA, and when I use the same syntax in Script Editor I get an "object required" error. When I try substituting objRange for Selection, I get "MoveRight" not supported".

I've looked around for VBScript Word object model references, but with no luck so far.
 
with [!]objWord.[/!]Selection

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks a million to tsuji and PHV - I knew I could count on the resident experts here!

One last question (so I can code better in the future):
any suggestions for a good VBScript reference for MS Office automation?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top