Solved

VBA Object and XHTML issue

Posted on 2011-03-16
6
1,384 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 83

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 83

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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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 83

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

786 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