1

作为 xlam 插件的一部分,我在 excel 2007 中创建了一个自定义 UI。自定义选项卡包含一个按钮,单击该按钮可打开网站。

我用了ThisWorkbook.followHyperlink "address"

该加载项受密码保护,每当我在 xlam 加载项中单击按钮时,都会导致 excel 崩溃。当我在 .xlsm 文件中使用它时,一切正常。

我认为问题在于ThisWorkbook受密码保护。我可以ActiveWorkbook改用,但是当没有打开工作簿时应用程序会崩溃。

有什么建议可以解决这个问题吗?(取消保护文件不是一种选择)

4

1 回答 1

1

包括来自评论的信息+假设只有在任何活动工作簿打开时才需要这样做......而不是您可以尝试以如下方式更改ThisworkbookActiveworkbook

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
于 2013-04-09T05:51:14.987 回答