vba - 暂停宏并让用户选择颜色

标签 vba excel

是否可以在打开格式单元格填充对话框时使该宏停止,以便我可以选择颜色并在选择“确定”时继续执行脚本。

Sub StripesOdd()

    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=MOD(ROW(),2)=1"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.14996795556505
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.Goto Reference:="StripesOdd"
End Sub

最佳答案

是的,这是可能的。在您继续沿着这条路走得太远之前 - VBA 是一种自动化工具。如果我是你,我会花更多时间根据数据设置颜色(即,如果字段等于“x”,则颜色为蓝色),而不是允许用户随机设置。如果需要人工干预,就不是自动化。

您需要将用户输入插入到代码中,要求用户在代码继续之前进行选择。

http://www.cpearson.com/Excel/Colors.aspx 上找到此内容 它确实需要 modColorFunctions bas 文件

Displaying A Color Picker Dialog

The modColorFunctions module contains a function named ChooseColorDialog that will display a Windows Color Picker dialog and return the RGB Long color value. If the user cancels the dialog, the result is -1. For example,

Dim RGBColor As Long
Dim Default As Long
Default = RGB(255, 0, 255) 'default to purple
RGBColor = ChooseColorDialog(DefaultColor:=Default)
If RGBColor < 0 Then
    Debug.Print "*** USER CANCELLED"
Else
    Debug.Print "Choice: " & Hex(RGBColor)
End If

当您希望用户输入颜色时,您需要插入对 ChooseColorDialog 的调用。

关于vba - 暂停宏并让用户选择颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19157277/

相关文章:

VBA:单击元素后无法更改图像控制图片

excel - Scripting.Dictionary 仍然在 VBA 中常用吗?

excel - 如何更改Excel VSTO加载项的显示名称?

excel - 用于抛硬币以获得特定模式的蒙特卡罗模拟

excel - 用于 Excel 的 VBA;编辑非常大的文件

vba - 根据另一个列表提取列表的子字符串

javascript - 使用 VBA 自动执行数据抓取以及在多框架 Intranet 网页内按下按钮

javascript - 我如何使用 Excel vba 从 javascript/CSS 网站中选择一个元素?

c++ - 使用Excel模板内的OleFunction“查找”查找 header 变量,然后从C++替换它们

excel - 在VBA中将两个大矩阵相乘