Using SendKeys with a Browser (1 Viewer)

ajetrumpet

Banned
Local time
Today, 13:19
Joined
Jun 22, 2007
Messages
5,638
Hey high-tech guys out there,

Is there anyway I can send a couple of keystrokes to a specific Firefox window that I have open ? I always have a certain textbox with the focus on a certain page, and every 20 minutes I would like to send two keystrokes via VBA to this page so it does not disconnect me for being idle. Can I be pointed in the right direction ? Google obviously turns up nothing. Either that, or too many irrelevant answers to come up with the right one. Thanks!


<edit>

In addition to what I have posted above, there is LOADS of information on how to automate IE with VBA, and I've found a ton, but I want this all with firefox. I know that IE is part of windows, so it IS an application object within the VB language. Can someone shed some light on how this is different for non-windows products ? Thanks!
 
Last edited:

HiTechCoach

Well-known member
Local time
Today, 13:19
Joined
Mar 6, 2006
Messages
4,357
Hey high-tech guys out there,

Is there anyway I can send a couple of keystrokes to a specific Firefox window that I have open ? I always have a certain textbox with the focus on a certain page, and every 20 minutes I would like to send two keystrokes via VBA to this page so it does not disconnect me for being idle. Can I be pointed in the right direction ? Google obviously turns up nothing. Either that, or too many irrelevant answers to come up with the right one. Thanks!


<edit>

In addition to what I have posted above, there is LOADS of information on how to automate IE with VBA, and I've found a ton, but I want this all with firefox. I know that IE is part of windows, so it IS an application object within the VB language. Can someone shed some light on how this is different for non-windows products ? Thanks!



Since you are using Firefox, I would recommend using something like AutoHotKey


I know that IE is part of windows, so it IS an application object within the VB language.
I do not think it has a lot to do with IE being integrated into the Windows OS. What makes IE usable with VB and VBA ( Access uses VBA not VB) or other programming languages, is that IE has an Application programming interface (API) that allows other programs to work with it. Firefox has just chose not to program in this ability. That is the reason why IE can be integrated into Windows.
 

ajetrumpet

Banned
Local time
Today, 13:19
Joined
Jun 22, 2007
Messages
5,638
Hello Hi Tech,

I have posted another thread close to this one here:

http://www.access-programmers.co.uk/forums/showthread.php?p=801312#post801312

I can figure this out pretty well with a little research, but I think the problem will be finding the names of the textboxes that I want to input text into. That thread is a bit useless, but it says a little more than I have posted here. Please take a look and let me know what you think I can do. thanks!
 

ShredDude

Registered User.
Local time
Today, 11:19
Joined
Jan 1, 2009
Messages
71
To determine the names of text boxes on the page, you need to read the HTML for the page. I've found that the Inspect Element feature of google's new Chrome browser is very good for this task. You can right click anywhere on the web page and chose Inspect Element to open a nice editor with the underlying HTML highlighted. Much nicer than the View Source method and pulling it up in a generic text editor like Notepad.

I'm not familiar with Firefox, but the task you're describing is very straight forward using IE with VBA, without using SendKeys.
 

Mike375

Registered User.
Local time
Tomorrow, 04:19
Joined
Aug 28, 2008
Messages
2,548
I'm not familiar with Firefox, but the task you're describing is very straight forward using IE with VBA, without using SendKeys.

Have you got a couple of snippets. I don't have the slightest idea how to "connect" to IE. I am assuming that it might be possible to insert a va,ue from Access textox to and IE screen??
 

ShredDude

Registered User.
Local time
Today, 11:19
Joined
Jan 1, 2009
Messages
71
Here's some snippets...

Code:
Public Sub IE()
'Requires Reference to the HTML Object Library

Dim IEapp As Object
  Dim IEdoc As Object
  Dim URL As String
  Dim myPageHtml As HTMLDocument
  Dim Htables As IHTMLElementCollection
  Dim myTable As IHTMLTable

Set IEapp = New InternetExplorer


' Create URL
    URL = "www.google.com"
        

' Go to the URL
      With IEapp
        .Visible = False
        .Navigate URL
      End With

' Wait for page to Load before proceeding

      While IEapp.Busy
        DoEvents
      Wend

'Grab the current page (not always necessary)...

    Set IEdoc = IEapp.document
        
        While IEapp.Busy
            DoEvents
        Wend
   
'Now you can do just about anything...


'Grab all the Tables on the page
    Set myPageHtml = IEdoc
    Set Htables = myPageHtml.getElementsByTagName("table")
    
    Set myTable = Htables(10) ' 11th Table contains what I need
    'will cause error here as I assume Google Home page doesn't have 11 tables...

'Grab what you need from table...

    For r = 1 To myTable.Rows.Count
        For c = 1 To 2 '
           vararray(r, c) = myTable.Rows(r).Cells(c).innerText
        Next c
    Next r

'set a Textbox value

    IEapp.document.controlx.Value = "myvalue"

'click a  button

    IEapp.document.buttonX.Click
    
'etc...

'Once you get access to the Document object, you can pretty much do anything...
'Good Luck with it...


'Clean up
     Set Htables = Nothing
     Set IEdoc = Nothing
     Set myPageHtml = Nothing
        
    IEapp.Quit
    
    
End Sub


To get you page to have new values in a text box every X minutes, you might write a wrapper routine that contains a timer function to kick off at whatever frequency you desire, calling your routine that will update your web page.

If since you opened that browser, you've opened others, you'll need to know which instance of IE your desired page is in. The Shell command can be used to grab all the open instances and you can loop through them to find the one containing your page with something like .locationURL = "myURL"
 

Mike375

Registered User.
Local time
Tomorrow, 04:19
Joined
Aug 28, 2008
Messages
2,548
Thanks for that. A few yellow highlights and bell rings:D but gives me the idea.
 

Mike375

Registered User.
Local time
Tomorrow, 04:19
Joined
Aug 28, 2008
Messages
2,548
I just found this.

Function stuff()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.google.com" 'load web page google.com
While ie.busy
DoEvents 'wait until IE is done loading page.
Wend
ie.Visible = True
'ie is now done loading the page
ie.Document.all("q").Value = "Australia and America"
'puts info into the inputbox named "q" which is google's search box.
ie.Document.all("btnG").Click 'clicks the button named "btng" which is google's "google search" button
While ie.busy
DoEvents 'wait until IE is done loading page.
Wend
'ie is now done loading the results page
End Function
 

ajetrumpet

Banned
Local time
Today, 13:19
Joined
Jun 22, 2007
Messages
5,638
Mike...I have already gotten this far. Thank anyway. The only thing I have left to figure out is how to insert the text into a text box. I can already open internet explorer and navigate to pages, print links, etc...

Pretty interesting, huh ?
 

Mike375

Registered User.
Local time
Tomorrow, 04:19
Joined
Aug 28, 2008
Messages
2,548
It looks like a SetValue type of deal

Document.all("q").Value = "Australia and America"

But how do you know the name of the box/control

Or the name of a button as in

Document.all("btnG").Click 'clicks the button named "btng" which is google's "google search" button
 

ajetrumpet

Banned
Local time
Today, 13:19
Joined
Jun 22, 2007
Messages
5,638
take a look at post #4 here Mike. I guess that is a great feature of google's new browser. As far as I know, that's the only way to find element names without sifting through hundreds of lines of HTML
 

ShredDude

Registered User.
Local time
Today, 11:19
Joined
Jan 1, 2009
Messages
71
You can also get at all the page's form control names with code.

Load up the page, then grab all the objects of the type you want in a previously Dim'd HTML Collection with a statement similar to this...

Code:
Set myHTMLColl = ieDoc.all.getelementsbytagname("the kind you want")

eg. "the kind you want" = "table", "button", "input", any valid HTML Tag Name, etc.

Then you can loop through your collection and do a debug.print stmt to output to the immediate window whatever attributes of the element you need. eg. .name, .innertext, etc.

Or, you can build a routine to enumerate any of the page's controls in any layout that is helpful to you. I find this easier to do in Excel. You can write the values to a spreadsheet to quickly get a look at what's on the page.

Once you've got that all broken out in front of you, you can then go back and code your routine to manipulate the element of the page you need.
 

Users who are viewing this thread

Top Bottom