如何使用 PowerPoint VBA 对跟随超链接执行错误检查?

How do I perform error-checking for following a hyperlink with PowerPoint VBA?

我正在使用 PowerPoint VBA 脚本通过超链接打开 pdf 文件,使用以下代码:

ActivePresentation.FollowHyperlink Address:=sFile

变量sFile只是一个带有本地文件路径的字符串,由前面的代码生成。我想制定某种防错措施,检查以确保在尝试访问超链接之前地址处有一个文件。如果文件路径不正确,我会收到一条错误消息 "Run-time error '-2147467259 (80004005)': Presentation (unknown member) : Cannot open the specified file."

本质上它是在告诉我该文件不存在(我发现这个错误是因为不小心让代码 运行 在它正确生成整个文件路径字符串之前打开超链接的行)。

无论如何,如果有人干涉并更改文件名,我希望得到一条信息性错误消息,而不是让脚本出错。

If Len(Dir$(sFile)) > 0 Then
  '' The file's there, follow the link
Else
  ' The file's missing
End if