Mouse Click Flush

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Douglas Barbará
    New Member
    • Dec 2010
    • 1

    Mouse Click Flush

    Good Morning,

    I need to develop a macro on Excell(VBA) that eventually will send multiple mouseclicks and work on the selected cells. Since the sheet it will work on doensn't have a recursive pattern to work but the screen itself, mouse clicks seems to be the way.

    I've browsed for information about moving the mouse cursor in VBA and it works, however the mouseclick I found only clicks on the end of the macro run, as if it was the last command of the macro.

    I'm using these API's and Excell 2007

    Code:
    Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    
    Declare Function mouse_event Lib "user32.dll" (ByVal dwflags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal dwData As Integer, ByVal dwExtraInfo As Integer) As Integer
    Is there a way to fix this issue?

    All clicks resume to just a single click in the end of the macro.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. Before getting to grips with the issue of mouse clicks, could you let us know why you need them?

    There is in general no requirement in VBA to physically select a cell by clicking on it before doing something with it. Even if there was there is a Select statement which is available for this purpose - you will see it used a lot if you examine code generated by the macro recorder in Excel.

    In VBA, cells are referenced as worksheet range objects. It is possible to do almost anything at all to any cell in any worksheet without the use of a mouse click - for example, it is possible to add a formula to a cell, set its background colour, set its formatting and so on without doing anything other than referring to the appropriate cell range directly, like this:

    Code:
    With ActiveSheet.Cells(1, 1)
      .Font.Bold = True
      .Formula = "=Sum(A2:A100)"
      .interior.colorindex = 34
    End With
    Not sure why whether or not a routine is recursive would mean using mouse clicks, but perhaps you could expand a little on what it is you need to do so we can guide you better?

    -Stewart

    Comment

    Working...