Select an option that is only possible through mouse click with vba

Asked

Viewed 1,312 times

3

I’m trying to develop a script with vba, no excel, to facilitate a routine we have at work, which inserts about 9,000 data into the internal system. Currently we manually enter this data. This data will never be the same, as it is obtained after several document checks.

As this system is a page, which we access by browser, I’m using the Application.SendKeys so I can manipulate him. He owns two logins. The first is quiet to do and after doing it, it shows us a selection of systems (as per the image below)

imagem

To access the second login, we have to select "PERSONAL". But it is only possible to select it using two mouse clicks. Press TAB and use arrows until you reach the option you need and then press ENTER does not resolve.

Would it be possible to make this click with VBA? I’ve seen that has something like .click, but I have no idea how I would do that.

The code to generate the picture frame, is below:

<!-- QUADRO DE SELECIONAR O SISTEMA-->
<span id="pnlUsuarioSistema_span" style = "position:absolute;top:210px;left:258px;height:197px;width:321px;background-color:F2F4F2;border-color:004080;border-style:Solid;border-width:1px;font-family:Verdana;font-size:11;font-style:normal;font-weight:normal;-moz-box-sizing:border-box;">
<label name="lblTexto" id="lblTexto" style = "background-color:F2F4F2;color:004080;font-family:Verdana;font-size:12;font-style:normal;font-weight:bold;height:21px;left:15px;position:absolute;top:15px;width:303px;">Selecione o sistema que deseja ingressar:</label>
<select  name="usrSysList" id="usrSysList" size="2" originalClass="DBList" style = "font-family:Verdana;font-size:12;font-style:normal;font-weight:normal;height:141px;left:17px;position:absolute;top:36px;width:285px;" ondblclick="openNewSession()">
<option value="http://(...)MAV">MAV</option>
<option value="http://(...)ORCOM">ORCOM</option>
<option value="http://(...)PESSOAL">PESSOAL</option>
</select>
</span>
<!-- FIM QUADRO -->
  • I didn’t understand the details of the problem. The system in the nevagador is developed by yourselves? This VBA is running in which tool? Would it be in Excel, for example? Something else (plus a hint): you have considered using the Autohotkey? Maybe it’s much simpler than trying to build something in VBA.

  • @Luizvieira I am writing the script in Excel. This system is very old, but it wasn’t developed by us. I didn’t know Autohotkey. It would be possible to use data from other software, such as an Excel spreadsheet?

  • I don’t think so. It essentially serves to automate manual tasks (like what I understood you wanted to do). You have data that accurate use/manipulate in Excel? This is not in the question. Anyway, I don’t know if the VBA can do what you want natively, but I don’t think so. However, it may be possible to play what Autohotkey does by importing native Apis from Windows. Take a look at the function SendInput.

  • 1

    Some examples that use this function to simulate keystrokes: http://www.mrexcel.com/forum/excel-questions/411552-sendinput-visual-basic-applications.html and http://stackoverflow.com/questions/13896658/sendinput-vb-basic-example; An example of Click (but it’s in VB, not in VBA): http://www.vbforums.com/showthread.php?734167-Mouse-Move-and-Click-with-Windows-API-Function-SendInput

  • Thanks, @Luizvieira. With these addresses you’ve passed, I think I’ll be able to write a routine, for what I need.

  • If you can, post yourself an answer here. Who knows helps someone else in the future. :)

Show 1 more comment

1 answer

2

I’ve been reading the links, which @Luizvieira made available and helped a lot, in understanding what I needed. But it was not possible to do exactly what I was looking for, for lack of knowledge of my.

That’s when I came to this link, that has the code below and it, in a different way, did what I needed but not as I would like. But the problem was solved.

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()
  '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()
  'Right Click
  SetCursorPos 200, 200 'x and y position
  mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.