我想匹配我的 UserForm5 的背景颜色,以匹配我(目标)单击的任何单元格的字体背景/填充颜色....vba 代码会执行此操作..谢谢..
这是新的,早期学习的日子。安迪摩尔
理想情况下,最好提供有关您在此处发帖时遇到的具体问题的更多详细信息,但因为我已经有了这个:
在
ThisWorkbook
代码模块中:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
SetFormColor Target.Cells(1) 'uses the first cell if >1 selected
End Sub
在常规代码模块中:
Option Explicit
Private f As frmInfo 'holds a reference to the opened form
Sub OpenForm()
Set f = New frmInfo
f.Show False '#show non-modally#
If TypeName(Selection) = "Range" Then 'initial color?
SetFormColor Selection.Cells(1)
End If
End Sub
Sub SetFormColor(c As Range)
If f Is Nothing Then Exit Sub 'exit if no open form
f.BackColor = c.DisplayFormat.Interior.Color 'DisplayFormat also includes Conditional Formatting
End Sub