Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write Data to Website Form using VBA 4

Status
Not open for further replies.

bdmangum

Technical User
Dec 6, 2006
171
0
0
US
I have website which has a textbox I would like populate and then a button I would like to click once the textbox is populated. I can get the code to click the button, but I can't seem to populate the textbox.

I can read the value of the textbox, but I am unable to write to it. I'm guessing this may be because the website requires data from the POST command? I know very little about using posting to fill in a website form data. Any help would be appreciated!

I'm afraid I can't post a link to the website as it would be pointless since it runs on a restricted access server.

Code:
Dim ieApp As Object, iePage As Object, READYSTATE_COMPLETE As Integer
READYSTATE_COMPLETE = 4
Set ieApp = CreateObject("InternetExplorer.Application")
ieApp.Visible = True
ieApp.Navigate "MyWebSite"
'wait for page to load
Do Until ieApp.ReadyState = READYSTATE_COMPLETE
Loop
Set iePage = ieApp.Document
strIn = "MyTextBoxData"
iePage.Forms("RAFTS_files").Item(0).Value = strIn  'Doesn't throw error, but doesn't populate either
MsgBox iePage.Forms("RAFTS_files").Item(0).Value 'Gives correct value if I pause macro and insert my own text manually
iePage.Forms("RAFTS_up").Item(".submit").Click  'This works
Set iePage = Nothing
Set ieApp = Nothing

Thanks!
BD
 
I just use sendkeys to tab to the field

Windows.Application.SendKeys "{TAB}"
SendKeys (strIn)
SendKeys "{ENTER}"

JB
 
JB,

Thanks for the reply, but I would like to avoid using the SendKeys approach. It can be too unreliable. If per chance the user happens to switch the focus to another application then something undesired could happen.

I'm thinking I need to use one of the things were the code is:

xxxx.Post URL, Value

I don't how to make the above work, or what to put in place of the xxx for Excel 2003.

BD
 
hmmm, I still can't get this to work. Anyone have ideas?
 
This is the last time I will bump this post up and I apologize for bumping it again, but I really need this capability for a program I'm writing at work. Does anyone have any ideas or websites with information on how to accomplish this task?
 
The companion of SendKeys is AppActivate (as clearly stated in the VBA help).

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Have you checked out this very good article by CMP at faq707-6399 where you can identify web page input boxes and write to them.
 
Thank you PHV (again) and TopJack for solving my problem with out even needing to post my problem!

AppActivate was the trick for me. I was using sendkeys but sending them where I do not know!!!!!

Using AppActivate is the solution.

thanks
 
Hi Poduska,

Could you please post the code for reference.

Stefen
 
Here is the Work In Progress.
I can get through my Login page by entering my PW and ID but when the new page, after login page, opens it hangs and no action seem to occur from that point. If I physically go to the new IE window and manualy press tab after the second page opens the "focus" appears to move from "nowhere" to the IE Address page but I cannot get the new web page to respond to any of the SendKeys I progromatically send to it via VBA and I have been stuck at that point.

There is a line I located at the end (exec wb) which prints the current page and I used it to know that I am REALLY on the page I wish to work.

Code:
Sub Webpage()

  Dim IE As Object
  Dim IEpage As Object
  Dim dummy As String
  
  Set IE = CreateObject("internetexplorer.application")
  IE.Visible = True
  With IE
    .Navigate "[URL unfurl="true"]https://Entire[/URL] web site address"
    Do Until IE.readystate = 4 'READYSTATE_COMPLETE
      'DoEvents
    Loop


  End With
  'Set IEpage = IE.Document
  
  AppActivate "Web Site Name here from title bar - Microsoft Internet Explorer", True
      Do Until IE.readystate = 4 'READYSTATE_COMPLETE
           DoEvents
      Loop
  
  SendKeys "Logon id", True
  Do Until IE.readystate = 4 'READYSTATE_COMPLETE
         DoEvents
  Loop

  SendKeys "{tab}", True
  Do Until IE.readystate = 4 'READYSTATE_COMPLETE
         DoEvents
  Loop

  SendKeys "Password", True
  Do Until IE.readystate = 4 'READYSTATE_COMPLETE
         DoEvents
  Loop

  SendKeys "{enter}", True
  Do Until IE.readystate = 4 'READYSTATE_COMPLETE
         DoEvents
  Loop
'AppActivate "next page after login page - Microsoft Internet Explorer", False
 
      Do Until IE.readystate = 4 'READYSTATE_COMPLETE
        DoEvents
      Loop
 
 SendKeys "{tab}", True
  Do Until IE.readystate = 4 'READYSTATE_COMPLETE
         DoEvents
  Loop

   SendKeys "{tab}", True
    SendKeys "{tab}", True
     SendKeys "{tab}", True
      SendKeys "{tab}", True
       SendKeys "{tab}", True
        SendKeys "{tab}", True
         SendKeys "{tab}", True


  IE.ExecWB 6, 2, 2, 0 OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER,PRINT_WAITFORCOMPLETION,0
  IE.Quit
  Set IE = Nothing
  Set IEpage = Nothing
  
End Sub

The AppActiveate was the trick to get me to be able to use the Login page and enter my ID and PW but no further.

good luck, let me know if you get anything to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top