Solved

VBA Object and XHTML issue

Posted on 2011-03-16
6
1,374 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:toecutter777
  • 3
  • 3
6 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 35151688
I'm getting a "HTTP Error 405.0 - Method Not Allowed" on both test2.htm and test3.htm.  The fact that it is not a complete and properly formatted web page may be part of the problem.  The DOCTYPE on test2.htm is not complete.  the complete version is below.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Untitled</title>
</head>
<body>

<form method="POST">
  <p><input type="text" name="theamount" size="20"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>
</html>

Open in new window

0
 

Author Comment

by:toecutter777
ID: 35153151
Yes, now that it is formatted properly that does not work. However, why would formatting it properly cause an error?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 35153199
It has not worked at all for me.  This is all I get for either page:
VBA405error.jpg
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:toecutter777
ID: 35153214
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 35153303
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.
0
 

Author Comment

by:toecutter777
ID: 35153358
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
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now