Unable to find object Form("Word")
I wanted to achieve, editing the recorded script, creating 5 word files with incremental names e.g. xyz0, xyz1...xyz4. So I added a for loop and changed the file name to accept a numerical at the end.
When I run the test, sometimes the script has managed to create 2 files xyz0, xyz1. But sometimes stops after 1 file. The error I get is: Unable to find the object Form("Word").
OS: Windows 8.1
The script is using coordinates to click, that is a different issue I have to solve.
Below is the edited script, any help is greatly appreciated, thanks!
function Test2()
{
var winword;
var form;
var netUIHWND;
var dlgSaveAs;
for (var i = 0; i < 5; i++)
{
Sys.Process("explorer").Window("Shell_TrayWnd").Window("ReBarWindow32").Window("MSTaskSwWClass", "Running applications").Window("MSTaskListWClass", "Running applications").Click(214, 27);
winword = Sys.Process("WINWORD");
form = winword.Form("Word");
form.Window("FullpageUIHost").Window("NetUIHWND").Click(548, 228);
form.Window("_WwF").Panel("Document1").Panel("Microsoft Word Document").Keys("Today is Thursday.");
form.Panel("MsoDockTop").ToolBar("Ribbon").Window("MsoWorkPane", "Ribbon").Window("NUIPane").Window("NetUIHWND").Click(38, 35);
netUIHWND = form.Window("FullpageUIHost").Window("NetUIHWND");
netUIHWND.Click(40, 201);
netUIHWND.Click(286, 283);
netUIHWND.Click(536, 210);
dlgSaveAs = winword.Window("#32770", "Save As");
dlgSaveAs.Window("DUIViewWndClassName").UIAObject("Explorer_Pane").Window("FloatNotifySink", "", 1).Window("ComboBox").SetText("xyz".concat(i));
dlgSaveAs.Window("Button", "&Save").ClickButton();
winword.Window("#32770", "Microsoft Word").Window("Button", "&Yes").ClickButton();
form.Close();
}
}