WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Word

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Create a Word-document with table


Question:

I've to write a script, the create a word-document with a table with 2 column. In the fist cell i have to fill some text from a winbatch Environment. in the second cell i've to put in a screen shot from the active windows. My problem is i have no idea above OLE, I find the Excel OLE Example.wbt, but i don't know the objects and classes for MSWord.

Answer:

Usually the easiest way to get started is to do it manualy with "record new macro" on { found in "Tools"|"Macro" then "adjust" the VBA code that the application has written, so that it works with winbatch.

Here is an attempt to help get you started.

filetocreate = "C:\temp\wordsamp.doc"

oAPP = ObjectOpen("Word.Application")
oDOC = oAPP.Application
oDOC.visible = @true
oDOC.ChangeFileOpenDirectory(FilePath(filetocreate))
oDocument =oDOC.Documents
oDocument.Add
oSelection = oDOC.Selection
oSelection.TypeText("Here is Your Table")

oRange = oSelection.Range
oActive = oDOC.ActiveDocument
oTables=oActive.Tables
wdWord9TableBehavior = 1
wdAutoFitFixed = 0		
 
oTables.Add(:: Range = oRange,NumRows=20,NumColumns=2,DefaultTableBehavior=wdWord9TableBehavior, AutoFitBehavior=wdAutoFitFixed)

;{Add code here to file table}

Pause("Debugging",StrCat("DONE - Check the contents of the file ",filetocreate))

oActive.SaveAs(StrCat(FileRoot(filetocreate),".",FileExtension(filetocreate)))

oActive.Close
oDOC.Quit

objectclose(oTables)
objectclose(oActive)
objectclose(oRange)
objectclose(oSelection)
objectclose(oDocument)
objectclose(oDOC)
objectclose(oAPP)

Article ID:   W16142
File Created: 2004:03:30:15:42:58
Last Updated: 2004:03:30:15:42:58