0

I have a script I am writing where I can execute a form on a website through a macro. I am able to open up internet explorer and pass all the variables correctly however when it comes time to submit, I am a bit lost.

this is the element on the website i want to click - it is a button titled "buy"

<input type="submit" name="submit" value="Buy">

I have two problems:

1) i don't know how to properly reference this within vba 2) there is a button right next to it that will perform a sell (the exact opposite of what i want to do) and the element for that is:

<input type="submit" name="submit" value="Sell">

Does anyone know appropriate code to hit the 'buy' button?

here is my code thus far:

Dim IE As Object
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate "somewebsite.com"

Do While IE.Busy: DoEvents: Loop
Do While IE.ReadyState <> 4: DoEvents: Loop
IE.Document.All("resourceoption").Value = "item"
IE.Document.All("amount").Value = 1
IE.Document.All("priceper").Value = 99
Do While IE.Busy: DoEvents: Loop
Do While IE.ReadyState <> 4: DoEvents: Loop
kamelkid2
  • 524
  • 3
  • 14
  • 29
  • it is for a game that i do not develop. i will be the only one using this sheet and it is an attempt to streamline the buying/selling process as it is very clunky and takes about 20 clicks through the current interface. this is not malicious in nature and is hardcoded for my account – kamelkid2 Dec 18 '14 at 15:16
  • possible duplicate of [VBA to Enter Data Online and Submit Form](http://stackoverflow.com/questions/17409613/vba-to-enter-data-online-and-submit-form) – SQLMason Dec 18 '14 at 15:17
  • @dan - this is close and I have been looking at previous SO topics on passing data to a website but the problem i am having specifically is regarding how this element is named. This link (nor any others i have found) addresses a button named in this manner – kamelkid2 Dec 18 '14 at 15:33

1 Answers1

0
With IE.document

    Set elems = .getElementsByTagName("input")
    For Each e In elems

        If (e.getAttribute("value") = "Buy") Then
            e.Click
            Exit For
        End If

    Next e

End With

the above snippet performs the task needed

kamelkid2
  • 524
  • 3
  • 14
  • 29