暂停宏,让用户选择颜色 [英] Pause macro and let user select color

查看:119
本文介绍了暂停宏,让用户选择颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在打开格式单元格填充对话框时停止此宏,以便选择颜色,并在选择OK时继续执行脚本。

  Sub StripesOdd()

Selection.FormatConditions.Add类型:= xlExpression,Formula1:= _
= MOD(ROW(),2)= 1
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.14996795556505
结束
Selection.FormatConditions(1).StopIfTrue = False
Application.Goto参考:=StripesOdd
End Sub


解决方案

是的,这是可能的。在继续下去这个路径之前,VBA是一个自动化工具。如果我是你,我会花更多的时间根据数据设置颜色(即如果字段等于x然后是蓝色),而不是允许用户随机地进行。如果需要手动干预,这不是自动化。



您需要在代码中插入用户输入,需要用户在代码继续前进行选择。 p>

http://www.cpearson .com / Excel / Colors.aspx
它需要modColorFunctions bas文件


显示颜色选择器对话框



modColorFunctions模块包含一个名为
的ChooseColorDialog,将显示一个Windows颜色选择器对话框,
返回RGB长颜色值。如果用户取消对话框,
结果为-1。例如,




  Dim RGBColor As Long 
Dim Default As Long
默认= RGB(255,0,255)'默认为紫色
RGBColor = ChooseColorDialog(DefaultColor:=默认)
如果RGBColor< 0然后
Debug.Print*** USER CANCELED
Else
Debug.PrintChoice:& Hex(RGBColor)
End If

您需要将调用插入到ChooseColorDialog中您希望用户输入颜色。


Is it possible to make this macro stop when it opens the format cells fill dialogue so I can choose the color and have the script continue when OK is selected.

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

解决方案

Yes it is possible. Before you continue down this path too far - VBA is an automation tool. If i was you, I'd spend more time on setting the colors based on data (ie if field equals "x" then color blue) rather than allowing the user do it randomly. It is not automation if manual intervention is required.

You need to insert a user input into the code which requires the user to make a selection before the codes continues.

Found this on http://www.cpearson.com/Excel/Colors.aspx It does requires the modColorFunctions bas file

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

You would need to insert the call to the ChooseColorDialog when you want the user to input the color.

这篇关于暂停宏,让用户选择颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆