+ Reply to Thread
Results 1 to 7 of 7

find image on the screen and click on it

  1. #1
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    71

    Question find image on the screen and click on it

    For automating external applications, as an easy fast (and temporary) way to find and click on certain elements, it would be useful to have some handy VBA functions that:

    1) find a given bitmap on the screen
    2) move the mouse on (the center of) it
    3) left click

    What libraries should I look at, to create these functions?

  2. #2
    Forum Contributor
    Join Date
    02-25-2022
    Location
    Dallas, Texas
    MS-Off Ver
    Office 365
    Posts
    174

    Re: find image on the screen and click on it

    Could you explain a little better what you are trying to do. Do you have a program running and you want to push a button on it automatically? I used AutoIT to do this. I also had to push a button on a graphic image. I did a screen capture of the screen using a command line tool called from VBA and did a search using a tool called Imagemagick (free, command line). It has a subimage search capability. Took a moment to figure it out but the forum is excellent. I remember it taking several seconds to find subimage. If it is a webpage there are better solutions.

  3. #3
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    71

    Re: find image on the screen and click on it

    Exactly, I used AutoIT and ImageSearch (see link1 and link2) in the past and I'd love to recreate the same in VBA that is my new preferred language

  4. #4
    Forum Contributor
    Join Date
    02-25-2022
    Location
    Dallas, Texas
    MS-Off Ver
    Office 365
    Posts
    174

    Re: find image on the screen and click on it

    There is no direct support in VBA. You'll need to use 3rd party tools and call them from VBA.

  5. #5
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: find image on the screen and click on it

    But what you can do, with difficulty, is find a button or other control in another applications window and click, mouse down or whatever on it. This is not beginner coding as it will involve extensive use of the Windows API. This depends on another application hosting child controls so am not sure what you mean by 'image'

    This, for example, is a VB sample to click a button in a known window. It first finds the Window from it's caption, then searches the child controls of that Window for a button with the caption "OK" and finally sends a Click event to the button. This is by far the simplest example I could find but it is Visual Basic not VBA so will have to be rewritten and that'll be a challenge in itself, but the basics are there.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    71

    Re: find image on the screen and click on it

    Quote Originally Posted by cytop View Post
    But what you can do, with difficulty, is find a button or other control in another applications window and click, mouse down or whatever on it. This is not beginner coding as it will involve extensive use of the Windows API. This depends on another application hosting child controls so am not sure what you mean by 'image'
    Yes I know but it's much more difficult and not always possible to find the control of an element.

    What I mean is that I'd like to give to VBA a little screenshot of something (a button or any other thing) that I want to click and let it find the coordinate of it on the screen.
    I wonder for example if there's a Windows API for that, or a way to use the nice third-party ImageSearch DLL used in AutoIT for that...

  7. #7
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: find image on the screen and click on it

    Quote Originally Posted by 6diegodiego9 View Post
    I'd like to give to VBA a little screenshot of something (a button or any other thing) that I want to click and let it find the coordinate of it on the screen.
    VBA works better with objects it can identify not a raw stream of bytes. Other than that, sorry, I really can't suggest anything.

+ 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. Formula stuck on screen as image
    By ebrewer27 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-26-2014, 01:23 PM
  2. Get mouse position on single click, use screen coordinates to place an image file
    By schmidt1962 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-01-2013, 02:57 AM
  3. [SOLVED] Pasting screen captured image on excel 2010
    By jonelamora in forum Excel General
    Replies: 4
    Last Post: 04-11-2013, 03:02 AM
  4. Save As PDF Image Does Not Utilize Full Screen
    By mgalterio in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2012, 04:57 PM
  5. saving an image of my screen
    By jt1561 in forum Excel General
    Replies: 2
    Last Post: 03-12-2009, 01:33 PM
  6. Scroll image across screen
    By Chard in forum Excel General
    Replies: 1
    Last Post: 09-22-2007, 03:11 PM
  7. why does ctrl+v paste an image of the screen?
    By GingerMagician in forum Excel General
    Replies: 0
    Last Post: 04-16-2006, 10:25 AM

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