Link to home
Start Free TrialLog in
Avatar of toecutter777
toecutter777

asked on

VBA Object and XHTML issue

It took me a long time to figure out why on some pages the following code works, while on others it does not. It appears that if the page is set to XHTML Doctype Transitional, I get an object error, otherwise it works fine. Any idea why? The webpage is set up to demonstrate. If you replace the webpage I have listed with test3.htm (the xhtml one, you'll see it does not function). I am running this from Excel VBA and REALLY would appreciate the help!

Sub test()
Dim userN As Variant
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://www.remtools.net/test2.htm"
Do While ie.busy
Loop
Set userN = ie.Document.getElementsByName("theamount")
If Not userN Is Nothing Then
    userN(0).Value = "1000"
End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toecutter777
toecutter777

ASKER

Yes, now that it is formatted properly that does not work. However, why would formatting it properly cause an error?
It has not worked at all for me.  This is all I get for either page:
VBA405error.jpg
Hi Dave,

I don't know why that would be happening, I loaded your adjusted code to the site? I am able to view the page properly in my browser.

Tim
Maybe we're talking about two different things.  Your pages displays correctly at first but I thought you were talking about clicking on "submit" and having something happen. ??

I don't know what "userN(0).Value = "1000"" is supposed to do.  Not now or before did I see anything like that on the page.
Oh, sorry, let me explain better. I am running the VBA code from and Excel worksheet, the submit button doesn't do anything except cause an error.

What happens is the vba macro is supposed to bring up the webpage and fill in 1000. This works for test2.htm but not test3.htm (the only real difference is that test2 does not have a doctype and test3 does).

You can try running the macro if you like, I've attached the file, just click the button. Then try changing the macro code to go to test3.htm and it returns an object error. test.xls