Link to home
Start Free TrialLog in
Avatar of Neil Fleming
Neil FlemingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

API calls to retrieve pixel color in Mac OS, using VBA

Struggling to figure out the Mac OS equivalent of the following WIndows API call declarations in VBA.

Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare PtrSafe Function GetPixel Lib "gdi32" (ByVal hdc As LongPtr, ByVal X As Long, ByVal Y As Long) As Long
Private Declare PtrSafe Function GetWindowDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr

Open in new window


I'm using the three in combination to retrieve a pixel color from wherever a Word user clicks on the screen. Any ideas?
Avatar of Eoin OSullivan
Eoin OSullivan
Flag of Ireland image

Neil

VBA in OSX is very, very limited and I'd be very surprised if its possible to achieve in VBA on OSX at all.

In effect the only fudge,workaround I can think of is to get an AppleScript to possibly get it on OSX

So in VBA you've to call an AppleScript which you're pre-created and saved in the scripts folder
https://docs.microsoft.com/en-us/office/vba/office-mac/applescripttask

Here is the type of script
https://macscripter.net/viewtopic.php?id=33268
Avatar of Neil Fleming

ASKER

Yes, I wondered about using a shell function via:

 Private Declare Function popen Lib "libc.dylib" (ByVal command As String, ByVal mode As String) As Long

Open in new window


Trouble is, the users really just want a simple Word Add-In, and don't want to go around installing other scripts, I suspect.

Also I notice running an Apple script may only work from Office 2016 for Mac. Not sure if all the users have it.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.