VBA : send a right-click to the application ?

Chris Davison

MrExcel MVP
Joined
Feb 15, 2002
Messages
1,790
is it possible to send a single mouse right-click to the application via VBA ?

I'm using sendkeys to get an accounting package to load up and print images but halfway through the procedure requires a mouse right-click on the image itself (no keyboard shortcut unfortunately), which I can't replicate via sendkeys

how would I therefore send a right-click ?

(help has "application.doubleclick" which looked promising, alas, nothing on "application.rightclick"....)

thanks
Chris
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
zilpher said:
Hi Chris...Here's some code

excellent.... this works a treat

nice anticipation of the need to position the cursor too, that was going to be my next question (!)

here's it's full use :

Rich (BB code):
Option Explicit
'===========================================================================
'MOUSECLICK CODE PROVIDED BY zilpher via www.mrexcel.com
'===========================================================================
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal Y As Long) As Long
Private 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)
    Private Const MOUSEEVENTF_LEFTDOWN = &H2
    Private Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
    Private Const MOUSEEVENTF_RIGHTUP As Long = &H10

Sub print_images()

    'declare variables
    Dim cell As Range
    
    'bring up test image 10006803 so you can use the F7 function on all others

    'activate Agresso
    AppActivate ("Agresso"), True
    'load enquiry
    Application.SendKeys ("~")
    'TAB to clear-all button
    Application.SendKeys ("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}")
    'hit clear-all button
    Application.SendKeys ("~")
    'TAB to transaction number indicator
    Application.SendKeys ("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}")
    'select transaction number indicator
    Application.SendKeys ("{F2} {TAB}")
    'TAB to transaction number
    Application.SendKeys ("{TAB}{TAB}{TAB}")
    'insert transaction number
    Application.SendKeys ("10006803")
    'TAB out
    Application.SendKeys ("{TAB}")
    'hit enter to run query
    Application.SendKeys ("~")
    'wait 2 seconds
    Application.Wait (Now + TimeValue("00:00:02"))
    'bring up tools menu
    Application.SendKeys ("%t")
    'select show invoice image
    Application.SendKeys ("~")
    'wait 10 seconds
    Application.Wait (Now + TimeValue("00:00:10"))

    'do actual images

    For Each cell In Range(ThisWorkbook.Worksheets("detail").Range("A65536").End(xlUp).Offset(1, 1), ThisWorkbook.Worksheets("detail").Range("B65536").End(xlUp))
        If cell.Value > 10000000 Then
            If cell.Value < 20000000 Then
                'load enquiry
                Application.SendKeys ("{F7}")
                'insert transaction number
                Application.SendKeys (cell.Text)
                'TAB out
                Application.SendKeys ("{TAB}")
                'hit enter to run query
                Application.SendKeys ("~")
                'wait 10 seconds
                Application.Wait (Now + TimeValue("00:00:10"))
                'perform right-click
                '===========================================================================
                'MOUSECLICK CODE PROVIDED BY zilpher via www.mrexcel.com
                '===========================================================================
                'move the cursor where you need it, I guessed at 200,200
                SetCursorPos 200, 200
                'send a down event
                mouse_event MOUSEEVENTF_RIGHTDOWN, 0&, 0&, 0&, 0&
                'and an up
                mouse_event MOUSEEVENTF_RIGHTUP, 0&, 0&, 0&, 0&
                'wait 2 seconds
                Application.Wait (Now + TimeValue("00:00:02"))
                'select best fit
                Application.SendKeys ("{DOWN}{DOWN}{DOWN}")
                'wait 2 seconds
                Application.Wait (Now + TimeValue("00:00:02"))
                'hit enter
                Application.SendKeys ("~")
                'perform right-click
                '===========================================================================
                'MOUSECLICK CODE PROVIDED BY zilpher via www.mrexcel.com
                '===========================================================================
                'move the cursor where you need it, I guessed at 200,200
                SetCursorPos 200, 200
                'send a down event
                mouse_event MOUSEEVENTF_RIGHTDOWN, 0&, 0&, 0&, 0&
                'and an up
                mouse_event MOUSEEVENTF_RIGHTUP, 0&, 0&, 0&, 0&
                'wait 2 seconds
                Application.Wait (Now + TimeValue("00:00:02"))
                'select best fit
                Application.SendKeys ("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")
                'wait 2 seconds
                Application.Wait (Now + TimeValue("00:00:02"))
                'hit enter
                Application.SendKeys ("~")
                'wait 10 seconds
                Application.Wait (Now + TimeValue("00:00:10"))
                'annotate image printed
                cell.Offset(-1, 0).Value = "image"
            End If
        End If
    Next cell
    
AppActivate "Microsoft Excel - Acquisitions 2004-05"
    
ThisWorkbook.Worksheets("detail").Select
Range("A1").Select
MsgBox ("All done.....")
    
End Sub

thanks zilpher, much appreciated
:-D
 
Upvote 0
Hello,

I appreciate that this is a very old thread but could be extremely helpful.

Chris you mentioned that you use Agresso via Citrix, I'm having problems getting this to work via Citrix, I instead have to use the version of agresso that is installed on the local machine.

Why not use the Agresso session that is installed on the local machine I hear you say...

I would prefer to get this working via Citrix as the response from the Servers is alot faster and easier to predict than if I was using the local client.

Thanks,
/Comf
 
Upvote 0
Agresso GL enquiry report accessing through Agresso accelerator?

Hi all,

I want to access a report (GL enquiry) through excel to would like to download the line items based on my input. Could you please advice me the code to download the line item into excel by using accelerator.

I want the code to give the input for CAT1, CAT4, period and amount.

Thanks in advance.

Regards,
Ram
 
Upvote 0
Hi rkesireddy,

Welcome to the board.

Is there a reason why you cannot export your GL Enquiry results from Agresso into Excel using the "Reports" function.

This is found in the "Data" toolbar menu.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top