excel vba followhyperlink方法当没有工作簿是开放的

我在Excel 2007中创build了一个自定义用户界面作为xlam加载项的一部分。 自定义选项卡包含一个button,可以在单击时打开网站。

我用ThisWorkbook.followHyperlink "address"

加载项是密码保护,导致excel崩溃,每当我点击button,而在xlam加载中。 当我在.xlsm文件中使用它时,一切正常。

我认为这个问题是在密码保护的ThisWorkbook 。 我可以使用ActiveWorkbook但是应用程序会在没有工作簿打开时崩溃。

任何build议如何我可以解决这个问题? (不保护文件不是一个选项)

包括来自评论的信息+假设只有在任何活动工作簿被打开的情况下才需要这样的信息……比如你可以尝试从这个工作簿改变成活动工作Thisworkbook ,就像这样:

 Sub FollowingHyperlink() 'check if there is anything open If Not ActiveWorkbook Is Nothing Then ActiveWorkbook.FollowHyperlink "http://www.stackoverflow.com" Else 'if not... it depends what you have and what you need 'you could just open any new workbook '**This part of code edited** 'or use this technique to navigate to page using IE: Dim ieAPP Set ieAPP = CreateObject("InternetExplorer.application") ieAPP.Visible = True ieAPP.navigate "http://www.stackoverflow.com" End If End Sub