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