vba 单元格内容的工具提示excel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17624501/
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-11 22:12:35  来源:igfitidea点击:

Tooltip of cell contents excel

excelvbahovercommentstooltip

提问by Slider105

I'm looking to find out how can i display a tooltip automatically in my tab "Sheet1", column "C9:10000", of all the cells that contain text (are not empty).

我正在寻找如何在包含文本(非空)的所有单元格的“Sheet1”选项卡、“C9:10000”列中自动显示工具提示。

The purpose of this is to browse through that column of cells and when they are active OR mouse over cell a tooltip would appear in a "baloon" type to display the entire text.

这样做的目的是浏览该列单元格,当它们处于活动状态或鼠标悬停在单元格上时,工具提示将以“气球”类型出现以显示整个文本。

thanks

谢谢

回答by Andy G

You could borrow the InputMessageof Data Validation:

你可以借用InputMessage数据验证:

Dim rng As Range

For Each rng In Range("B2:B10")
    With rng.Validation
        .Delete
        .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, _
            Operator:=xlBetween
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .InputMessage = rng.Text
        .ShowInput = True
        .ShowError = True
    End With
Next rng

(empty cells will be ignored)

(空单元格将被忽略)

You have to click in the cell though, and there is a limitation to the max. number of characters (I haven't checked what this is yet. Added: 254 characters).

但是,您必须单击单元格,并且最大值有限制。字符数(我还没有检查这是什么。添加:254 个字符)。

Use Left(rng.Text, 254)in the above code as this is the maximum length in the InputMessage, and any more will cause an error.

Left(rng.Text, 254)在上面的代码中使用,因为这是 InputMessage 中的最大长度,否则会导致错误。

BTW Most of the properties in the above code are likely to be optional - I borrowed this from a recorded macro.

顺便说一句,上面代码中的大多数属性可能是可选的 - 我从录制的宏中借用了它。