Solved

VBA Object and XHTML issue

Posted on 2011-03-16
6
1,389 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 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