vba 在 MessageBox 中放置超链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28705916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:24:29  来源:igfitidea点击:

Putting a hyperlink in a MessageBox

vbahyperlinkaccess-vbams-access-2010messagebox

提问by Johnny Bones

Is it possible to add a hyperlink to a messagebox? I'm trying to do something like this:

是否可以向消息框添加超链接?我正在尝试做这样的事情:

   MsgBox "Sorry, but you have an out-of-date database version.  Please redownload via the batch file to ensure that you have the latest version. Contact the administrator of this database or your manager if you need help." & vbCr _
        & vbCr _
        & "Your current database version is " & CurrentVer & " which may be out of date. The current database version prescribed on the network share is " & FileVer & ". They must match in order for you to proceed." & vbCr _
        & vbCr _
        & "For CSC self-help instructions on how to reload the most current version of the PRF Intake Tool to your computer, please click the link below to be directed to CSC Online instructions." & vbCr _
        & vbCr _
        & "http://www.OurSite.com/online/Solutions/Search_Results.asp?opsystem=7&keywords=PRF+Intake+Tool&Category=", , "There is a problem..."

The problem is, the hyperlink isn't clickable. I'd like to do this so that the users can just click the link and have the download begin automatically.

问题是,超链接不可点击。我想这样做,以便用户只需单击链接即可自动开始下载。

I'm using Access 2010 in a Win7 environment.

我在 Win7 环境中使用 Access 2010。

回答by Wiktor Stribi?ew

A straight-forward answer is NO. MsgBox does not allow hyperlinks, just plain text.

一个直接的答案是NO。MsgBox 不允许超链接,只有纯文本。

Thus, here is a workaround that should work alright.

因此,这是一个应该可以正常工作的解决方法。

Set objShell = CreateObject("Wscript.Shell")

intMessage = MsgBox("Sorry, but you have an out-of-date database version.  Please redownload via the batch file to ensure that you have the latest version. Contact the administrator of this database or your manager if you need help." & vbCr _
        & vbCr _
        & "Your current database version is " & CurrentVer & " which may be out of date. The current database version prescribed on the network share is " & FileVer & ". They must match in order for you to proceed." & vbCr _
        & vbCr _
        & "Would you like to learn more about CSC self-help instructions on how to reload the most current version of the PRF Intake Tool to your computer?", _
        vbYesNo, "There is a problem...")

If intMessage = vbYes Then
    objShell.Run ("http://www.OurSite.com/online/Solutions/Search_Results.asp?opsystem=7&keywords=PRF+Intake+Tool&Category=")
Else
    Wscript.Quit
End If

If underline style is a requirement, then you should just create your own User Form as described at http://j-walk.com/ss/excel/tips/tip71.htm. Here are the steps:

如果需要下划线样式,那么您应该创建自己的用户表单,如http://j-walk.com/ss/excel/tips/tip71.htm 所述。以下是步骤:

  1. Add a Labelobject and type your message
  2. Make the Label blue (ForeColor) and underlined (Font) so it looks like a typical hyperlink.
  3. Set the Label's MousePointerproperty to 99 - fmMousePointerCustom
  4. Specify the cursor file for the Label's MouseIconimage (if you have one).
  5. Double-click the Label and create a subroutine the Clickevent. Here's a sample code:

    Private Sub Label1_Click()
      Link = "http://www.YOUR_SITE.com"
      On Error GoTo NoCanDo
      ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
      Unload Me
      Exit Sub
     NoCanDo:
      MsgBox "Cannot open " & Link End Sub
    
  1. 添加一个Label对象并输入您的消息
  2. 将标签设为蓝色 ( ForeColor) 并加下划线 ( Font),使其看起来像一个典型的超链接。
  3. 将 Label 的MousePointer属性设置为99 - fmMousePointerCustom
  4. 指定标签MouseIcon图像的光标文件(如果有)。
  5. 双击标签并创建一个子程序Click事件。这是一个示例代码:

    Private Sub Label1_Click()
      Link = "http://www.YOUR_SITE.com"
      On Error GoTo NoCanDo
      ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
      Unload Me
      Exit Sub
     NoCanDo:
      MsgBox "Cannot open " & Link End Sub
    

To create a "mail to" hyperlink, use a statement like this:

要创建“mail to”超链接,请使用如下语句:

Link = "mailto:[email protected]"