用WSH批量修改当前文件夹中所有ppt的链接

将下面的内容保存为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进行调试
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值