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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to connect to a website through a macro? 1

Status
Not open for further replies.

asianinvasian

Technical User
Jul 10, 2007
10
US
Hello, New to this site. Just signed up :D
i've been browsing the forums and i found a whole bunch of information i can use at work with Extra! personal client 6.5
What i haven't ran into is how to send information to a website.
At work we have a site that we enter what we completed.
Lets say i complete paperwork1, i need to copy paperwork1. go to the site put in the name, paperwork1, and then click a listbox( i think thats what they are called) and then put if its done or needs to be worked on.

how can i accomplish this through a macro?
 
Code:
sURL = "[URL unfurl="true"]http://www.google.com"[/URL]
Set oIE = CreateObject("InternetExplorer.Application")
oIE.navigate(sURL)
oIE.visible = True
While oIE.Busy
Wend
Set oElements = oIE.Document.GetElementsByTagName("input")
For i = 0 to oElements.Length - 1
    Set oElement = oElements(i)
    oElement.Value = "Test " & i
Next

A list box is a "select" tag. With a list box you'll also have to enumerate the oElement.Options.Length and do a oOption.Selected = True to change the item selected.
 
Should oElements and oIE be Dim as Object?
i also get an error when i compile the code in the macro editor for the for statement.
 
Yes, try
Code:
Sub Main

    Dim oIE as object
    Dim oElement as object
    Dim oElements as object

    sURL = "[URL unfurl="true"]http://www.google.com"[/URL]
    
    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.navigate(sURL)
    oIE.visible = True
    
    While oIE.Busy
        Doevents
    Wend
    
    Set oElements = oIE.Document.GetElementsByTagName("input")
    
    For i = 0 to oElements.Length - 1
        Set oElement = oElements(i)
        oElement.Value = "Test " & i
    Next

End Sub
Have a star Skie!

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.
 
Awesome Thanks! i got it to populate the fields i want.
How do i make the button click? or submit
 
Sub Main
Dim oIE as object
Dim oElements as object
Dim oElement as object

sURL = " Set oIE = CreateObject("InternetExplorer.Application")
oIE.navigate(sURL)
oIE.visible = True


While oIE.Busy
DoEvents
Wend

oIE.document.all.Item(74).Click


End Sub

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.
 
Alright i got that to work on google. is there a way to figuer out which item(x) the submit button is on my site?
 
asianinvasian,
It's probably safer (easier?) to call the control by name:
[tt]oIE.document.all.Item("btnG").Click[/tt]

To get the name you can dig through the HTML, open the webpage in Word/MSE or any other HTML editor which should show the control name.

This might also be of some interest (read: shameless plug).

[tab]faq707-6399

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
A list box is a "select" tag. With a list box you'll also have to enumerate the oElement.Options.Length and do a oOption.Selected = True to change the item selected."

i'm a bit confused on this part acutally still. Not quite sure how to go with this.
 
I'm having trouble posting this (for 2 days now, so I'm going to split it up and see if that helps.

I don't know what your HTML looks like. It should be within a form and have a name and/or id. If you look at the HTML source you should find something similar to this.
Code:
<form id="myForm">
  <select id="myID" name="myID">
    <option>Option 1
    <option>Option 2
    <option>Option 3
  </select>
</form>
 

If you know the ID you can simply do:
Set oSelect = oIE.Document.myID

If the <select> tag is within a form tag you may need to include it:
Set oSelect = oIE.Document.myForm.myID

If there is no ID, but the best way to obtain the element is:
Set oSelect = oIE.Document.GetElementsByName("myID")

If there isn't an ID or name, then you'll have get the elements by tag name. See my first response and change "input" to "select". Anyhow, once you have your object, you now need to indicate which item is selected.
Code:
For i = 0 to oSelect.Options.Length -1
    Set oOption = oSelect.Options(i)
    If oOption.Text = "Option 2" Then
        oOption.Selected = True
    End If
Next

If you have a list box that allows multiple selections, and you want to unselect something, you would change the True to a False.

Hope this helps.
 
If you do a CreateObject instead of a GetObject do you still get the error? What happens with this code?
Code:
Sub DisplaySessionCount
  Dim System As Object
  Set System = CreateObject("EXTRA.System")
  If System Is Nothing Then
    MsgBox "Unable to acquire EXTRA! system object."  Else
  Else
    MsgBox System.Session.Count
  End If
End Sub
 
CreateObject works fine. I’m now running into another problem.

oSelect.Text = camp
oSelect2.Text = "Incomplete"
I have two select fields. One is for camp and the other is the status (oSelect2)
The camp is all numbers. So I have that working just fine.
However the status(oSelect2) are strings. Such as “complete” “incomplete” “call” stuff like that.
When I do oSelect2.Text = “Incomplete” it doesn’t select it, just makes another instance of it in the drop box. So when I hit submit it gives me an error that I haven’t selected a Status, even tho it shows “Incomplete” it doesn’t take it in as one.


And thank you guys so much for the help so far. Learning a lot and able to create a lot of useful macros.
 
Oh also that code on the web page, for me its
<select name=”var”> <option value=''>Choose Option</option>
<option >Complete</option>
option >Incomplete</option>
<option >Incomplete - Need Call</option>
 
Skie said:
With a list box you'll also have to enumerate the oElement.Options.Length and do a oOption.Selected = True to change the item selected.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 

For i = 0 to oSelect.Options.Length -1
Set oOption = oSelect.Options(i)
If oOption.Text = "Incomplete" Then
oOption.Selected = True
End If
Next


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Thank you to everyone who gave me tips :) or really wrote most of it haha.
 
I'm running in to a problem..

Set oElements = oIE.Document.GetElementsByName("var1")

'1 is the field for app ID
Set oElement = oElements(1)

oElements.Value = Ref

the last line of this code errors out sometimes and states
that the object value is set to nothing.
this error comes randomly. works for a while then error.
Any idea why?
 
If you only have 1 element in oElements, you shouldn't need to use a oElements(1). Another thing is, with the way elements are counted they may start at 0. Anyhow, the best thing to do is make sure you actually have something.
Code:
Set oElements = oIE.Document.GetElementsByName("var1")
If oElements Is Nothing Then
  MsgBox "You don't have your oElement."
Else
'do your code
End If

When you get the error the site may not be entirely loaded. Make sure you wait for the site to load. There a .busy and there's another property similar to .busy that you may want to use.

Another posiblity is the site didn't load. You may want to setup some sort of navigation function to renavigate to the site if your element is nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top