hi,
we have a major problem at work. We had a large number of templates that
were scattered across many servers, which we have just consolidated on to 1
server in departmental directories. This works great when creating new
documents based on templates on the new server. The problem is that when we
did the re-organization we switched off the unused servers. Now if you try to
open a document that was created before the change, Word hangs for abour 10
minutes. I assume it is looking for its attached template (on a now
non-existent server). The templates all still exist in the new location (in
various sub directories). Everybody's Workgroup Templates setting is set to
the new location as well.
any help would be appreciated as this causing a major problem,
Chris
On Thursday, May 01, 2008 9:17 AM Terry Farrell wrote:
The solution is to use the Windows server Redirect command to redirect calls
for the old templates to the new server location. If you need help with
this, ask in an appropriate Windows Server Newsgroup.
On Thursday, June 19, 2008 6:20 PM Chri wrote:
The attached script will traverse a tree of folders searching for *.doc and
upon discovery will open each and reset the attached template to
"normal.dot". Cut the code out and paste it into "traverse.js" and copy this
file to the root directory where you want to fix all the documents. It will
leave "traverse.log" in the "current" directory. Investigation of my log
file showed that I was spending almost five minutes waiting for the timeout.
I believe that you must run it on a machine which has Word installed. Three
are three sections commented out which you can deply and they will tell a
small amount about the progress but these are not as good as the log file, so
I recommend that you leave them as they are.
There is nothing delicate about this script, but it works well. I fixed
25,000 documents...
//
// Traverse a document tree and execute for each "*.doc" discovered
//
function main()
{
var d;
if (WScript.Arguments.count()>0)
{
d = WScript.Arguments.Item(0);
}
else
{
var fs = new ActiveXObject("Scripting.FileSystemObject");
d = fs.GetFolder(".");
}
traverse(d);
}
function traverse(d)
{
var w = new ActiveXObject("Word.Application");
var cmd = new ActiveXObject("WScript.shell");
// if (cmd.Popup(d, 1, "Directory", 64 + 1) == 2)
// {
// var log = fs.OpenTextFile("traverse.log", 8, true);
// log.WriteLine("Quit:[" + ts() + "] " + s);
// log.Close();
//
// w.Quit(0);
// w = null;
// WScript.Quit();
// }
var fs = new ActiveXObject("Scripting.FileSystemObject");
var f = new Enumerator(fs.GetFolder(d).files);
for ( ; !f.atEnd(); f.moveNext())
{
var e = f.item().Name.split(".");
if (e[e.length-1].toUpperCase() != "DOC"){continue;}
// if (cmd.Popup(f.item().Name, 1, "Document Found", 64 + 1) == 2)
// {
// var log = fs.OpenTextFile("traverse.log", 8, true);
// log.WriteLine("Quit:[" + ts() + "] " + s);
// log.Close();
//
// w.Quit(0);
// w = null;
// WScript.Quit();
// }
//
// I have a document ... Repair the attached template
//
var s = f.item().ParentFolder + "\\" + f.item().Name;
var log = fs.OpenTextFile("traverse.log", 8, true);
log.WriteLine("Open:[" + ts() + "] " + s);
log.Close();
var doc = w.Documents.Open(s);
// if (cmd.Popup(f.item().Name, 1, "Document Opened", 64 + 1) == 2)
// {
// var log = fs.OpenTextFile("traverse.log", 8, true);
// log.WriteLine("Quit:[" + ts() + "] " + s);
// log.Close();
//
// w.Quit(0);
// w = null;
// WScript.Quit();
// }
doc.AttachedTemplate = "normal.dot";
w.Dialogs(87).Execute();
doc.Save();
doc.Close();
var log = fs.OpenTextFile("traverse.log", 8, true);
log.WriteLine("Done:[" + ts() + "] " + s);
log.Close();
}
w.Quit(0);
w = null;
var f = new Enumerator(fs.GetFolder(d).SubFolders);
for ( ; !f.atEnd(); f.moveNext())
{
traverse(f.item().ParentFolder + "\\" + f.item().Name);
}
}
function ts()
{
var t = new Date();
var hr = "0" + t.getHours(); hr = hr.substr(hr.length-2, 2);
var mn = "0" + t.getMinutes(); mn = mn.substr(mn.length-2, 2);
var sc = "0" + t.getSeconds(); sc = sc.substr(sc.length-2, 2);
return(hr + ":" + mn + ":" + sc);
}
main();