Excel VBA:未为Shape对象(msoPicture)调用WorkSheet_FollowHyperlink [英] Excel VBA : WorkSheet_FollowHyperlink is not getting called for Shape Object ( msoPicture )

查看:660
本文介绍了Excel VBA:未为Shape对象(msoPicture)调用WorkSheet_FollowHyperlink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有人单击工作表中的图片时,我需要执行一个宏.宏的意图是显示有关用户单击的形状的更多信息. 我还需要在鼠标悬停时显示信息,因此使用了超链接方法.

I need to have a macro executed when someone clicks on the shape in the worksheet which is a picture. The macro intention is to display more information regarding the shape on which the user clicked. I also needed an information display during mouse-rollover, hence used hyperlink method.

我遵循了

I followed the method outlined in the MSDN , but the macro just doesn't seem to run.

我的宏如下:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
  MsgBox "Source: Target.Range.Address  " & Target.Range.Address
  MsgBox "Source: Target.Range.Value " & Target.Range(1, 1).Value
  ' Some more macro stuff here
End Sub

  • 单击图片后,我会到达超链接目标所在的工作表 是,但是宏不会执行.
  • 如果在其中一个单元格(在同一张纸上)上创建了一个虚拟超链接,如果单击该宏,则会执行该宏.
  • 我使用超链接方法在图片形状上显示了翻转信息.
    • On clicking the picture I get to the sheet where the hyperlink target is, but the macro doesn't get executed.
    • I created a dummy hyperlink on one of the cells (in the same sheet), if I click that one the macro is executed.
    • I used the hyperlink method to have the rollover information on the picture shape.
    • 我完全不知道该怎么做.帮助将不胜感激.

      I am totally out of ideas about how to go about this. Help would be greatly appreciated.

      推荐答案

      请勿使用该方法.使用Worksheet_SelectionChange代替Worksheet_FollowHyperlink.

      Don't use that method. Use Worksheet_SelectionChange instead of Worksheet_FollowHyperlink.

      因此将您的代码更改为

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
          '~~> Change A1 to the cell which is behind the shape
          If Not Intersect(Target, Range("A1")) Is Nothing Then
              '~~> Change this to the relevant sheet
              With ThisWorkbook.Sheets("Sheet1")
                  .Visible = xlSheetVisible
                  .Activate
              End With
      
              '
              '~~> Other Code if required
              '
          End If
      End Sub
      

      下一步,右键单击形状,然后单击Hyperlink并超链接到形状后面的单元格.您也可以使用Insert hyperlink对话框中的ScreenTip按钮显示信息.

      Next, Right Click on the Shape and click on Hyperlink and hyperlink to a cell behind the shape. You may also display information using the ScreenTip button in the Insert hyperlink dialog box.

      我们将在上面的代码中完成工作表激活部分,而不是让Excel完成.

      We will do the sheet activating part in the above code rather than letting Excel do it.

      希望这可以解决您的问题.

      Hope this solves your issue.

      这篇关于Excel VBA:未为Shape对象(msoPicture)调用WorkSheet_FollowHyperlink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆