将下面的内容保存为app.js
var app = WScript.CreateObject("PowerPoint.Application");
app.Visible = true;
var fso = WScript.CreateObject("scripting.filesystemobject");
var logfile = fso.CreateTextFile("log.txt", true);
var orginAddr,newAddr,arr,filePath
var folder = fso.GetFolder(".");
var e = new Enumerator(folder.files);
outer:
for (; !e.atEnd(); e.moveNext()){
var file = e.item();
if(file.Path.indexOf(".ppt") > 0){
app.Presentations.open(file.Path,false);
app.Activate();
for(var i = 1; i <= app.ActivePresentation.Slides.Count; i++){
if(!app.ActivePresentation.Slides.Item(i).Hyperlinks)continue;
for(var j = 1; j <= app.ActivePresentation.Slides.Item(i).Hyperlinks.Count; j++){
orginAddr = app.ActivePresentation.Slides.Item(i).Hyperlinks.Item(j).address;
if(orginAddr.indexOf("html") > 0){
if(orginAddr.indexOf("/") > 0){
arr = orginAddr.split("/");
}else{
arr = orginAddr.split("\\");
}
newAddr = "../../" + arr[arr.length - 1];
app.ActivePresentation.Slides.Item(i).Hyperlinks.Item(j).address = newAddr ;
//记录失效链接
if(!fso.FileExists(newAddr)){
logfile.WriteLine(file.Name + "\t幻灯片:" +i + ","+ j +" \t" + app.ActivePresentation.Slides.Item(i).Hyperlinks.Item(j).address);
}
}
}
}
app.ActivePresentation.save();
app.ActivePresentation.close();
}
}
logfile.close();
在命令行中运行wscript /x app.js进行调试