问题已经解决!在MS VB帮助中找到答案,即在可能发生错误之前加入On Error Resume Next语句!
RIyJ68ME.rar
(22.52 KB, 下载次数: 8)
请解压在D:\ljwt\下运行
Sub aa()
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\a.xls", NewName:="D:\ljwt\a.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\b.xls", NewName:="D:\ljwt\a.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\c.xls", NewName:="D:\ljwt\a.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\d.xls", NewName:="D:\ljwt\a.xls", Type:=xlExcelLinks
End Sub
Sub bb()
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\a.xls", NewName:="D:\ljwt\b.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\b.xls", NewName:="D:\ljwt\b.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\c.xls", NewName:="D:\ljwt\b.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\d.xls", NewName:="D:\ljwt\b.xls", Type:=xlExcelLinks
End Sub
Sub cc()
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\a.xls", NewName:="D:\ljwt\c.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\b.xls", NewName:="D:\ljwt\c.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\c.xls", NewName:="D:\ljwt\c.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\d.xls", NewName:="D:\ljwt\c.xls", Type:=xlExcelLinks
End Sub
Sub dd()
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\a.xls", NewName:="D:\ljwt\d.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\b.xls", NewName:="D:\ljwt\d.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\c.xls", NewName:="D:\ljwt\d.xls", Type:=xlExcelLinks
On Error Resume Next
ActiveWorkbook.ChangeLink Name:="D:\ljwt\d.xls", NewName:="D:\ljwt\d.xls", Type:=xlExcelLinks
End Sub
Resume Next:如果错误和错误处理程序出现在同一个程序中,则从紧随产生错误的语句的下个语句恢复运行。如果错误发生在被调用的过程中,则对最后一次调用包含错误处理程序的过程的语句(或 On Error Resume Next 语句),从紧随该语句之后的语句处恢复运行。
但还不是很理想,代码太长,能不能在不知当前链接(包括范围)的情况下切换链接,假设选提取当前链接"X"
ActiveWorkbook.ChangeLink Name:="X", NewName:="D:\ljwt\d.xls", Type:=xlExcelLinks
请高手解答!
[此贴子已经被作者于2004-5-20 7:25:37编辑过] |