Pause macro and let user select color

前端 未结 1 1165
长情又很酷
长情又很酷 2021-01-20 16:02

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.



        
相关标签:
1条回答
  • 2021-01-20 16:28

    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.

    0 讨论(0)
提交回复
热议问题