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