MACRO - Retrieve Color Values from Selected Object

Any way with a macro to get color info and output text for example

CMYK color

C=125   M=58  Y=14  K=0

Parents Reply
  • Any way to pass this data into the clip board?

    This is some code that I have used; where it came from is noted in the comments.

    You can put that in a module in your project, and then have the ClipBoard_SetData function available to use.

    Private Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
    Private Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
    Private Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As LongPtr, ByVal dwBytes As LongPtr) As LongPtr
    Private Declare PtrSafe Function CloseClipboard Lib "user32" () As LongPtr
    Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
    Private Declare PtrSafe Function EmptyClipboard Lib "user32" () As LongPtr
    Private Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As LongPtr
    Private Declare PtrSafe Function SetClipboardData Lib "user32" (ByVal wFormat As LongPtr, ByVal hMem As LongPtr) As LongPtr
    
    Const GHND = &H42
    Const CF_TEXT = 1
    
    Function ClipBoard_SetData(MyString As String)
    'PURPOSE: API function to copy text to clipboard
    'SOURCE: www.msdn.microsoft.com/en-us/library/office/ff192913.aspx
    
    Dim hGlobalMemory As LongPtr, lpGlobalMemory As LongPtr
    Dim hClipMemory As LongPtr, X As LongPtr
    
    'Allocate moveable global memory
      hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
    
    'Lock the block to get a far pointer to this memory.
      lpGlobalMemory = GlobalLock(hGlobalMemory)
    
    'Copy the string to this global memory.
      lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
    
    'Unlock the memory.
      If GlobalUnlock(hGlobalMemory) <> 0 Then
        MsgBox "Could not unlock memory location. Copy aborted."
        GoTo OutOfHere2
      End If
    
    'Open the Clipboard to copy data to.
      If OpenClipboard(0&) = 0 Then
        MsgBox "Could not open the Clipboard. Copy aborted."
        Exit Function
      End If
    
    'Clear the Clipboard.
      X = EmptyClipboard()
    
    'Copy the data to the Clipboard.
      hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
    
    OutOfHere2:
      If CloseClipboard() = 0 Then
        MsgBox "Could not close Clipboard."
      End If
    
    End Function
    

    There may be something different/newer/better out there, but I haven't looked recently.

    Here's something: Send information to the Clipboard.

Children