繁体   English   中英

没有打开工作簿时的excel vba followhyperlink方法

[英]excel vba followhyperlink method when no workbook is open

我在Excel 2007中创建了一个自定义UI,作为xlam加载项的一部分。 自定义标签包括一个按钮,单击该按钮即可打开网站。

我用了ThisWorkbook.followHyperlink "address"

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

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

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

包括评论+假设,即当任何activeworkbook是开放这个只需要工作...不是你可以尝试从改变信息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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM