设置 UserForm5 背景以匹配 ClickedON 单元格字体背景/填充颜色?

问题描述 投票:0回答:1

我想匹配我的 UserForm5 的背景颜色,以匹配我(目标)单击的任何单元格的字体背景/填充颜色....vba 代码会执行此操作..谢谢..

这是新的,早期学习的日子。安迪摩尔

excel vba
1个回答
0
投票

理想情况下,最好提供有关您在此处发帖时遇到的具体问题的更多详细信息,但因为我已经有了这个:

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
© www.soinside.com 2019 - 2024. All rights reserved.