[英]Floating Message/Comment Box
So pretty much what I am trying to do is create a floating text box that would be on the right of the spreadsheet. 因此,我几乎要做的就是在电子表格的右侧创建一个浮动文本框。 When a user selects a row/cell it will then place a comment or message with details about that cell in there rather than a small little comment box. 当用户选择行/单元格时,它将在其中放置带有有关该单元格详细信息的注释或消息,而不是一个小的小注释框。
I have tried to use the UserForm Box but its not really what I'm looking for. 我试图使用UserForm Box,但它并不是我真正想要的。
Example: 例:
User Selects Cell A4, I would like a message to read in a floating text when that cell is selected. 用户选择单元格A4,当选择该单元格时,我希望显示一条以浮动文本形式显示的消息。 Then if a user selects Cell B6 a different message appears in that box. 然后,如果用户选择单元格B6,则该框中将显示另一条消息。
Does that makes sense? 这有意义吗?
Update: 更新:
The Following Code Shows a UserForm box when a certain cell is selected: 当选定某个单元格时,以下代码显示一个“用户窗体”框:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Definition As String
If Intersect(Target, Range("C6:D6")) Is Nothing Then Exit Sub
Select Case Target.Row
Case 22
Definition = "Text Here"
Case 23
Definition = "Text Here Again"
End Select
UserForm1.Label1.Caption = Definition
UserForm1.Show
End Sub
I don't want to use a UserForm box as its not stationary on the Worksheet itself. 我不想使用UserForm框,因为它在工作表本身上不是固定的。 I want it so a Text Box that always appears on the right hand side of the worksheet to display a set message or context when the cell is selected. 我希望它是一个始终显示在工作表右侧的文本框,以在选择单元格时显示设置的消息或上下文。 It will be different then what is stored in the actual cell. 这将与实际单元格中存储的内容不同。
Use a Data Validation message. 使用数据验证消息。 This type of message "pops-up" whenever you click on a cell: 每当您单击一个单元格时,这种消息就会“弹出”:
You can place a Label or TextBox control directly in the worksheet - make sure it's an ActiveX control, not a Forms control - and position it dynamically using the worksheet's SelectionChange event: 您可以将Label或TextBox控件直接放置在工作表中-确保它是ActiveX控件,而不是Forms控件-并使用工作表的SelectionChange事件将其动态放置:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Me.lblText
.Visible = False
Select Case Target.Row Case 22 .Caption = "Text Here Again" Case 23 .Caption = "Text Here Again" Case Else .Visible = False Exit Sub End Select
' Place the label to the right of the target cell .Left = Target.Left + Target.Width
' Or place the label in the far left of the window '.Left; =; Application.ActiveWindow.VisibleRange.Width; -; .Width
.Top = Target.Top - 0.75 ' cell borders
.Visible = True
End With
End Sub
Some hints: 一些提示:
I strongly advise you to set the background colour of the control to &H80000004&, the predefined Windows scheme colour for menu and form backgrounds; 我强烈建议您将控件的背景色设置为&H80000004&,这是菜单和表单背景的预定义Windows方案颜色; likewise, the foreground to &H80000008&, the menu text colour. 同样,菜单文本颜色&H80000008&的前景。 This ensures visibility for users who have their own colour settings, and explicitly supports users who specify an accessible or assistive colour scheme to ameliorate a visual impairment. 这样可以确保具有自己的颜色设置的用户的可见度,并明确支持指定可访问或辅助的配色方案以改善视觉障碍的用户。
My code relies on your sheet supporting event procedures in VBA, and on ActiveX controls. 我的代码取决于您的工作表支持VBA中的事件过程以及ActiveX控件。 It won't work in .xlsx sheets, and it may be blocked (or accompanied by warning dialogues) if your operating environment has a heavy-handed security policy. 它无法在.xlsx工作表中使用,并且如果您的操作环境具有严格的安全策略,则可能会被阻止(或伴随警告对话框)。
Copy-and-paste might be affected by my use of the Worksheet SelectionChange event. 复制和粘贴可能会受到我对工作表SelectionChange事件的使用的影响。
Me.lblText.Visible = False
You might draw an obvious conclusion from all this: the native comment or data validation label is a better bet than using forms and ActiveX controls. 您可能会从所有这些中得出一个显而易见的结论:本机注释或数据验证标签比使用表单和ActiveX控件更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.