Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:55:59+00:00 2026-06-14T18:55:59+00:00

What I try to do is: 1. goto `worksheet 4` 2. right mouse click

  • 0

What I try to do is:

1. goto `worksheet 4`
2. right mouse click on cell `D32`
3. if (first time): 
      a. choose import text file.
   else:
      b. choose the Refresh 
  • Is there any more elegant way to do it except of using
    mouse_events ?
  • If I use mouse_events I have to simulate one left and one right click. How can I make sure to make the right click on the exact place on the menu? I thought to use spy++ but it seems to be a wrong and dirty way to do simple thing.

====The SOURCE CODE from the link to simulate the mouse events: ====

Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10

Private Sub SingleClick()
  SetCursorPos 100, 100 'x and y position
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

Private Sub DoubleClick()
  'Simulate a double click as a quick series of two clicks
  SetCursorPos 100, 100 'x and y position
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

Private Sub RightClick()
  'Simulate a right click
  SetCursorPos 200, 200 'x and y position
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:56:02+00:00Added an answer on June 14, 2026 at 6:56 pm

    Is there any more elegant way to do it except of using mouse_events ?

    Yes there is. Use the Worksheet_BeforeRightClick event

    Also in the below example, i am checking if there is any contents in Cell D32 to decide whether to import or to refresh. You may use a boolean variable if you want to.

    The code goes in the sheet code area of the relevant sheet. See screenshot.

    SCREENSHOT

    enter image description here

    CODE

    Option Explicit
    
    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
        On Error GoTo Whoa
    
        Application.EnableEvents = False
    
        '~~> Check if the right click happened on D32
        If Not Intersect(Target, Range("D32")) Is Nothing Then
            '~~> Check if cell is empty
            If Len(Trim(Target.Value)) = 0 Then
                '~~> If empty, import file
            Else
                '~~> if not empty, refresh data
            End If
            Cancel = True
        End If
    
    LetsContinue:
        Application.EnableEvents = True
        Exit Sub
    Whoa:
        MsgBox Err.Description
        Resume LetsContinue
    End Sub
    

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm having a problem with Crystal Reports where the first time I try
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
try { if (myBoolean) { while (true) ; } else { System.exit(1); } }
i try to make a loop in a .cmd file. If test.txt is not
Here's a trivial batch: @echo off if not .%1==.-b goto else echo Running with
I can't see any memory change in my .map file when I try to
Is it bad practice use try-catch like goto? For example, simple code try{ if(argc<2){
try {... block: .... } catch{ ..} GOTO block ... .... finally{...} Will goto
After submitting a search query to a php file I try to go back
I try to create a batch file to automaticaly rename the files contained in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.