473,466 Members | 1,363 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fill a form from excel?

20 New Member
Hi everyone

So this is my question...

I need to log in so many times in so many computers, in a specific web page "http://webshipping.dhl.com.mx"

I wold like to do it with a macro Im using Excel 2003

By now, I have the next code, But doesnt seems to work, please help me...



Expand|Select|Wrap|Line Numbers
  1. Sub pag()
  2.  
  3. Dim myie As New InternetExplorer 'New'
  4. Dim mydoc As HTMLDocument
  5. Dim myurl, usuario As String
  6. Dim ieform As Object
  7.  
  8. myurl = "http://webshipping.dhl.com.mx"
  9. usuario = "User"
  10.  
  11. myie.navigate myurl
  12. myie.Visible = True
  13.  
  14. 'esperar a que cargue la página
  15. Do While myie.Busy Or myie.ReadyState <> READYSTATE_COMPLETE
  16. DoEvents
  17. Loop
  18.  
  19. 'MsgBox myie.LocationName
  20.  
  21.  
  22. Set mydoc = myie.Document
  23. mydoc.forms(0).UserName.Value = usuario ' i get an error here
  24.  
  25. ' code for set the password must be here
  26.  
  27. 'code for submit the form is here
  28.  
  29. 'MsgBox "pausa p/ver si escribió"
  30. 'mydoc.forms [0].submit
  31.  
  32. Do While myie.Busy Or myie.ReadyState <> READYSTATE_COMPLETE
  33. DoEvents
  34. Loop
  35.  
  36. MsgBox myie.LocationName
  37.  
  38.  
  39. End Sub
Sep 24 '10 #1
4 2464
cynicon
20 New Member
Hello, is anybody there?
Oct 8 '10 #2
Guido Geurs
767 Recognized Expert Contributor
To open a webpage in Excel:

Expand|Select|Wrap|Line Numbers
  1. Sub launchIE()
  2. ActiveWorkbook.FollowHyperlink Address:="http://www.google.ca", NewWindow:=False
  3. ActiveWorkbook.FollowHyperlink Address:="http://www.yahoo.ca", NewWindow:=False
  4. End Sub
For Your URL it will be:

Expand|Select|Wrap|Line Numbers
  1. Sub launchIE()
  2. ActiveWorkbook.FollowHyperlink Address"http://webshipping.dhl.com.mx", NewWindow:=False
  3. End Sub
Oct 8 '10 #3
danp129
323 Recognized Expert Contributor
Checking to see if the browser is finished is always a pain especially in frames or redirects. I've left your checks but added my own, then showed how to populate the textboxes and submit the form.
Expand|Select|Wrap|Line Numbers
  1. ' References: 1) MS Internet Controls. 2) MS HTML Object Library
  2. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  3.  
  4.  
  5. Const PROCESS_TIMEOUT = 20  ' Seconds to wait for procedure to fail on errors
  6.  
  7. Sub pag()
  8. Dim StartTime As Date
  9. Dim myie As New InternetExplorer 'New'
  10. Dim mydoc As HTMLDocument
  11. Dim myurl As String
  12. Dim ieform As IHTMLFormElement
  13. Dim usuario As String
  14. Dim Contrasena As String
  15.  
  16. StartTime = Now()
  17.  
  18. usuario = "User"
  19. Contrasena = "Password"
  20.  
  21. myurl = "http://webshipping.dhl.com.mx"
  22.  
  23. myie.navigate myurl
  24. myie.Visible = True
  25.  
  26. 'esperar a que cargue la página
  27. Do While myie.Busy Or myie.ReadyState <> READYSTATE_COMPLETE
  28. DoEvents
  29. Loop
  30.  
  31. ' Wait until submit button is found or our process times out
  32. Dim testElement As IHTMLElementCollection
  33. Do
  34.     ' Look for submit button, exit loop if we find it
  35.     On Error Resume Next
  36.     Set mydoc = myie.Document
  37.     Set testElement = mydoc.getElementById("loginform").getElementsByTagName("input")
  38.  
  39.     If testElement Is Nothing Then
  40.         Sleep (100) ' Wait 1/10th second
  41.     Else
  42.         ' We've found the form and some inputs, if the submit button is found then exit do
  43.         If LCase(testElement.Item(testElement.Length - 1).Value) = "ingresar" Then Exit Do
  44.     End If
  45.  
  46.     ' Check time process has taken, if more than user specified, close browser and exit loop
  47.     If DateDiff("s", StartTime, Now()) >= PROCESS_TIMEOUT Then
  48.         Set mydoc = Nothing
  49.         Set testElement = Nothing
  50.         myie.Quit
  51.         Set myie = Nothing
  52.         MsgBox "Failed to login to website, user specified timeout of " & PROCESS_TIMEOUT & " seconds has been exceeded."
  53.         Exit Sub
  54.     End If
  55. Loop
  56.  
  57. On Error GoTo 0
  58.  
  59. Dim formInputs As IHTMLElementCollection
  60. Set ieform = mydoc.getElementById("loginform")
  61.  
  62. ieform("j_username", 0).Value = usuario
  63. ieform("j_password", 0).Value = Contrasena
  64. ieform.submit
  65.  
  66.  
  67. Do While myie.Busy Or myie.ReadyState <> READYSTATE_COMPLETE
  68. DoEvents
  69. Loop
  70.  
  71. MsgBox myie.LocationName
  72.  
  73.  
  74. End Sub
  75.  
Oct 12 '10 #4
cynicon
20 New Member
danp129, you are my hero, it works perfectly, I really appreciate the time you dedicate to reply my question

Thank you so much

Cheers
Oct 13 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Scott | last post by:
Hi there, I have a PDF that has editable form fileds. I want to be able dynamically fill in those form fields based on values I provide to the PDF. Right now, I can create an instance of the...
1
by: mikeybe | last post by:
Making a very simple library circulation database for a school project. I have a Patron Information table(patronID, first name, last name, phone) , an item information table (bookID, book title,...
2
by: Joanne Lewis | last post by:
I am having a great deal of difficulty with a form. Basically, I would like to enter an account # and have the account #, patient first name, and patient last name automatically fill. The form...
2
by: Jason Huang | last post by:
Hi, In my C# windows form project, how do I use an existing Excel 2000 as a template? Thanks for help. Jason
19
by: Alex | last post by:
Hello list This question has probably already been asked, but let me ask again I have a mysql database to which I connect with my php scripts. The database contains articles. Name, Unit_Price...
0
by: limipl | last post by:
Hello, How may I pass in VBA a value from a control in a access 2003 form to a control in a excel 2003 form ? I try this but it does'nt run: (oApp=word.application)...
1
by: cmcl95 | last post by:
HI Folks, I need some help I'm trying to develop a automated way to import from a excel spsh excluding the 1st 2 rows & two out of 41 columns. I got the 1st part with range see below ...
1
by: Nosferatum | last post by:
I tried to combine a script which process a web form and mails the result, and at the same time stores the entered info into a excel-file on the server. But I just can't make it work. Does it exist...
106
by: bonneylake | last post by:
Hey Everyone, Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all...
7
by: ghjk | last post by:
I have table which is clickable.When user click one record I want to call java script function and fill the form using selected values. This is my code and I can't understand what is going...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.