Solved

VBA Object and XHTML issue

Posted on 2011-03-16
6
1,398 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 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