Forum Discussion
HKosova
Alumni
12 years agoWord automation is so much easier when using the Word COM object, Word.Application.
For your task, something like this should do the trick:
For your task, something like this should do the trick:
function Create5WordFiles()
{
// 1. Get the Desktop folder path
var oShell = Sys.OleObject("WScript.Shell");
var strDesktop = aqFileSystem.IncludeTrailingBackSlash(oShell.SpecialFolders("Desktop"));
// 2. Create 5 Word files on the desktop
var oWord = Sys.OleObject("Word.Application");
var oDoc, strFileName;
for (var i = 0; i < 5; i++)
{
// Create a blank document
oDoc = oWord.Documents.Add();
// Enter text into the document
oDoc.Range(0, 0).Text = "Today is Thursday.";
// Save the file to Desktop
strFileName = strDesktop + "xyz" + i + ".docx";
oDoc.SaveAs(strFileName);
oDoc.Close();
}
oWord.Quit();
}