Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default sendkeys to a launched IE browser

Code is simple... and there is no error in code (that VBA discerns) but the
sendkeys commands do not move the cursor in the new IE window and doesn't
send the active cell value either. Any thoughts?

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://whatever.com"
.resizable = True
End With

'App.Activate "Microsoft Internet Explorer"
SendKeys "{TAB}"
SendKeys ActiveCell.Value
SendKeys "~"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default sendkeys to a launched IE browser

John, are you trying to fill in a form on a webpage or send a command to the
browser itself (such as "open page www.123.com)?

If you are trying to fill in a form on a page, my first guess is that you
aren't waiting long enough for the page to fully load. With the following
code I was able to browse to www.funny.com and enter "test" into the search
box. Sendkeys is very finicky and I would only use it as a last resort. If
the web page orientation (layout, tab-index, etc.) ever changes, your code
will break.

Regards,
Bill




Public Sub Test_IESendkeys()
Dim i As Long
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://www.funny.com"
.resizable = True
End With

Application.Wait (Now + TimeValue("0:00:10"))

'App.Activate "Microsoft Internet Explorer"
For i = 1 To 15
SendKeys "{TAB}"
Next i

SendKeys "test"
'SendKeys "~"
End Sub







"John" wrote:

Code is simple... and there is no error in code (that VBA discerns) but the
sendkeys commands do not move the cursor in the new IE window and doesn't
send the active cell value either. Any thoughts?

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://whatever.com"
.resizable = True
End With

'App.Activate "Microsoft Internet Explorer"
SendKeys "{TAB}"
SendKeys ActiveCell.Value
SendKeys "~"

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default sendkeys to a launched IE browser

Thanks for the response Bill... it was a time thing... I am trying to launch
a new window and then dump a cell value into a search on a website. This
works by adding that wait command...

I realize that if the website changes the code is no good... is there a way
around that?

"Bill Pfister" wrote:

John, are you trying to fill in a form on a webpage or send a command to the
browser itself (such as "open page www.123.com)?

If you are trying to fill in a form on a page, my first guess is that you
aren't waiting long enough for the page to fully load. With the following
code I was able to browse to www.funny.com and enter "test" into the search
box. Sendkeys is very finicky and I would only use it as a last resort. If
the web page orientation (layout, tab-index, etc.) ever changes, your code
will break.

Regards,
Bill




Public Sub Test_IESendkeys()
Dim i As Long
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://www.funny.com"
.resizable = True
End With

Application.Wait (Now + TimeValue("0:00:10"))

'App.Activate "Microsoft Internet Explorer"
For i = 1 To 15
SendKeys "{TAB}"
Next i

SendKeys "test"
'SendKeys "~"
End Sub







"John" wrote:

Code is simple... and there is no error in code (that VBA discerns) but the
sendkeys commands do not move the cursor in the new IE window and doesn't
send the active cell value either. Any thoughts?

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://whatever.com"
.resizable = True
End With

'App.Activate "Microsoft Internet Explorer"
SendKeys "{TAB}"
SendKeys ActiveCell.Value
SendKeys "~"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default sendkeys to a launched IE browser

Rather than use SendKeys, you should be interacting with the web page
directly. For example, something like:

Set oIE = New InternetExplorer
oIE.Visible = True
oIE.Navigate Range("sURL")
Do: DoEvents: Loop Until oIE.ReadyState = READYSTATE_COMPLETE

Set oForm = oIE.Document.forms(0)
oForm("name1").Value = "Value1"
oForm("name2").Value = "Value2"
oForm("submitname").Click
Do: DoEvents: Loop While oIE.Busy
Do: DoEvents: Loop Until oIE.ReadyState = READYSTATE_COMPLETE

Set oForm = oIE.Document.forms(0)
oForm("cancelname").Click

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default sendkeys to a launched IE browser

Firstly, let me disclaim my reference to www.funny.com. I have no
accociation with the site - it just happened to be the site that popped up
when I entered "whatever.com".

If the objects on the page are tagged, you can get a better "grip" when
you're trying to access them. You can find out by looking at the page source
and try to find a name property. In the "funny.com" site, you'll see that
the search field has a name: <input class="formItem" size="10" type=text
value="" name="0.7.31.1.3". You can "tie" to this object with more
elaborate code. You will still be at the mercy of the site designers if they
change the control name, but it is considerably more reliable than using the
tab index.

I haven't written code tie directly to an object embedded in a webpage,
although I know sample code is out there.



"John" wrote:

Thanks for the response Bill... it was a time thing... I am trying to launch
a new window and then dump a cell value into a search on a website. This
works by adding that wait command...

I realize that if the website changes the code is no good... is there a way
around that?

"Bill Pfister" wrote:

John, are you trying to fill in a form on a webpage or send a command to the
browser itself (such as "open page www.123.com)?

If you are trying to fill in a form on a page, my first guess is that you
aren't waiting long enough for the page to fully load. With the following
code I was able to browse to www.funny.com and enter "test" into the search
box. Sendkeys is very finicky and I would only use it as a last resort. If
the web page orientation (layout, tab-index, etc.) ever changes, your code
will break.

Regards,
Bill




Public Sub Test_IESendkeys()
Dim i As Long
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://www.funny.com"
.resizable = True
End With

Application.Wait (Now + TimeValue("0:00:10"))

'App.Activate "Microsoft Internet Explorer"
For i = 1 To 15
SendKeys "{TAB}"
Next i

SendKeys "test"
'SendKeys "~"
End Sub







"John" wrote:

Code is simple... and there is no error in code (that VBA discerns) but the
sendkeys commands do not move the cursor in the new IE window and doesn't
send the active cell value either. Any thoughts?

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://whatever.com"
.resizable = True
End With

'App.Activate "Microsoft Internet Explorer"
SendKeys "{TAB}"
SendKeys ActiveCell.Value
SendKeys "~"



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default sendkeys to a launched IE browser

John,
Depending on how this server handles the input, can you .Navigate2 the URL
that would exist after you have entered the criteria and clicked the button
?
e.g. This link takes you directly to Googles results page
http://www.google.co.uk/search?hl=en...=Google+Search

You can build the required string with your ActiveCell.Value and go there
directly.

NickHK

"John" wrote in message
...
Code is simple... and there is no error in code (that VBA discerns) but

the
sendkeys commands do not move the cursor in the new IE window and doesn't
send the active cell value either. Any thoughts?

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie

.Visible = True

.navigate "http://whatever.com"
.resizable = True
End With

'App.Activate "Microsoft Internet Explorer"
SendKeys "{TAB}"
SendKeys ActiveCell.Value
SendKeys "~"



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
In Excel, why does my VB not work when launched from IE ? David C Excel Programming 3 March 21st 06 09:46 AM
converting ppt to pdf launched from xls pm[_2_] Excel Programming 12 January 6th 06 11:05 PM
converting ppt to pdf launched from xls pm[_2_] Excel Programming 0 January 5th 06 11:33 PM
How do I determine how excel was launched Gilgamesh[_2_] Excel Programming 2 January 21st 05 07:04 AM
Can you tell how Excel is launched? Gail Hurn Excel Programming 3 January 11th 05 05:47 PM


All times are GMT +1. The time now is 04:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"