+ Reply to Thread
Results 1 to 9 of 9

"open-ended" format macro

Hybrid View

  1. #1
    Registered User
    Join Date
    12-27-2012
    Location
    Greece, NY
    MS-Off Ver
    365
    Posts
    63

    "open-ended" format macro

    Hi,

    I want to create a macro that gets me to the Custom Color window of Format Cells, then leaves me there in order to make my color selection. I don't know how to stop recording the steps at that point, or if it's even possible.

    Help please

    Excel 2010 Professional
    Win 7Prof, 64 bit

  2. #2
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: "open-ended" format macro

    Maybe I'm thinking too simply, but...?

    Sub GetColors()
    Application.Dialogs(xlDialogPatterns).Show
    End Sub

  3. #3
    Registered User
    Join Date
    12-27-2012
    Location
    Greece, NY
    MS-Off Ver
    365
    Posts
    63

    Re: "open-ended" format macro

    I'll give it a try and let you know.

  4. #4
    Registered User
    Join Date
    12-27-2012
    Location
    Greece, NY
    MS-Off Ver
    365
    Posts
    63

    Re: "open-ended" format macro

    I realize I need one more step: I want to end up in the More Colors window.

  5. #5
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: "open-ended" format macro

    How's this?

    
    Sub test()
    Dim intColor As Long
    
    Application.Dialogs(xlDialogEditColor).Show (1)
    intColor = ThisWorkbook.Colors(1)
    Selection.Interior.Color = intColor
    
    End Sub

  6. #6
    Registered User
    Join Date
    12-27-2012
    Location
    Greece, NY
    MS-Off Ver
    365
    Posts
    63

    Re: "open-ended" format macro

    It's good, but when I got to it, I realized that where I really need to be is on the Custom tab. Willing to make the third time the charm? Sorry for not being clear about where I want to end up.

  7. #7
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: "open-ended" format macro

    And of course I immediately find a shorter version...

    
    Public Sub ActiveCellColourPicker()
     
        ' // defines a Constant Long pallet index which is 32, the last Colour for the Custom pallet
        Const PALLET_INDEX As Long = 32
     
        ' // defines a Constant Long default Colour used to initialse the RGB for the Edit Colour Dialog
        Const DEFAULT_COLOUR As Long = 15790320
     
        ' // defines a Double used to store the original ActiveWorkbook Colour for the Constant PALLET_INDEX
        Dim dbOriginalColourIndex As Double
     
        ' // defines a Double used to store the selected Colour from the Edit Colour Dialog
        Dim dbNewColourIndex As Double
     
        ' // store the original ActiveWorkbook Colour for the Constant PALLET_INDEX
        dbOriginalColourIndex = ActiveWorkbook.Colors(PALLET_INDEX)
     
        ' // initialise the Edit Colour Dialog
        If Application.Dialogs(xlDialogEditColor).Show(PALLET_INDEX, _
                                                       (DEFAULT_COLOUR And 255), _
                                                       (DEFAULT_COLOUR \ 256 And 255), _
                                                       (DEFAULT_COLOUR \ 256 ^ 2 And 255)) = True _
                                                       And Not (ActiveWorkbook.Colors(PALLET_INDEX) = 1) Then
     
            ' // retrive the new ActiveWorkbook Colour for the Constant PALLET_INDEX
            dbNewColourIndex = ActiveWorkbook.Colors(PALLET_INDEX)
     
            ' // set the ActiveCell to the chosen Colour
            Selection.Interior.Color = dbNewColourIndex
     
            ' // reset the ActiveWorkbook Colour for the Constant PALLET_INDEX
            ActiveWorkbook.Colors(PALLET_INDEX) = dbOriginalColourIndex
     
        End If
     
    End Sub

  8. #8
    Registered User
    Join Date
    12-27-2012
    Location
    Greece, NY
    MS-Off Ver
    365
    Posts
    63

    Re: "open-ended" format macro

    Perfect!

    Thank you SO much.

  9. #9
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: "open-ended" format macro

    Third time is a LOT more difficult, it seems. I struck out for a while before finding a solution crafted by a far more capable colormaster. To give credit where it's due, pretty much all of the heavy lifting here was pulled from an outside post by vba_corner. All three of the pieces below will need to be included, but the Sub you'll want to call is named CustColor().

    
    Function PickNewColor(Optional i_OldColor As Double = xlNone) As Double
    Const BGColor As Long = 13160660  'background color of dialogue
    Const ColorIndexLast As Long = 32 'index of last custom color in palette
    
    Dim myOrgColor As Double          'original color of color index 32
    Dim myNewColor As Double          'color that was picked in the dialogue
    Dim myRGB_R As Integer            'RGB values of the color that will be
    Dim myRGB_G As Integer            'displayed in the dialogue as
    Dim myRGB_B As Integer            '"Current" color
      
      'save original palette color, because we don't really want to change it
      myOrgColor = ActiveWorkbook.Colors(ColorIndexLast)
      
      If i_OldColor = xlNone Then
        'get RGB values of background color, so the "Current" color looks empty
        Color2RGB BGColor, myRGB_R, myRGB_G, myRGB_B
      Else
        'get RGB values of i_OldColor
        Color2RGB i_OldColor, myRGB_R, myRGB_G, myRGB_B
      End If
      
      'call the color picker dialogue
      If Application.Dialogs(xlDialogEditColor).Show(ColorIndexLast, _
         myRGB_R, myRGB_G, myRGB_B) = True Then
        '"OK" was pressed, so Excel automatically changed the palette
        'read the new color from the palette
        PickNewColor = ActiveWorkbook.Colors(ColorIndexLast)
        'reset palette color to its original value
        ActiveWorkbook.Colors(ColorIndexLast) = myOrgColor
      Else
        '"Cancel" was pressed, palette wasn't changed
        'return old color (or xlNone if no color was passed to the function)
        PickNewColor = i_OldColor
      End If
    End Function
    
    'Converts a color to RGB values
    Sub Color2RGB(ByVal i_Color As Long, o_R As Integer, o_G As Integer, o_B As Integer)
      o_R = i_Color Mod 256
      i_Color = i_Color \ 256
      o_G = i_Color Mod 256
      i_Color = i_Color \ 256
      o_B = i_Color Mod 256
    End Sub
    
    Sub CustColor()
        Selection.Interior.Color = PickNewColor
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Excel 2010 -- "Visual Basic" "Macros" and "Record Macro" all disabled.
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2017, 06:11 AM
  2. Activating unsaved open workbook using "if "name" like "name" satement
    By joshuarobbins in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2015, 11:17 AM
  3. [SOLVED] Must open and close UserForm twice for the other codes in the "Open..." Macro to execute
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-10-2013, 09:28 AM
  4. Replies: 0
    Last Post: 09-09-2013, 12:30 PM
  5. Date format of just "st" "nd" "rd" and "th" with text included
    By notrandom in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-10-2013, 05:45 PM
  6. How can i copy value from "HTMLText"(EMBED("Forms.HTML:Text","")),using Macro
    By andrewyang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2010, 12:47 AM
  7. Replies: 0
    Last Post: 01-04-2006, 06:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1