From: MartinL on
I'm also including the first few lines of the source code of the web page.
Maybe there's something there that could give you a clue. . . .


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title id="htmTitle">Defect List Report</title>
<base target="_self">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="/defaultscreen.css" type="text/css" rel="stylesheet">
<script language="javascript">
//**************************************************************
//Pop up window when Submit button is click
//**************************************************************
//
function UnloadWin(){
}

From: AB on
If you comment out the msgbox does this:

..getElementById("selSavedReports").Value = 932

still fire the run-time error?
From: AB on
if this:

> If you comment out the msgbox does this:
>
> .getElementById("selSavedReports").Value = 932
>
> still fire the run-time error?

still doesn't work and because i'm running out of ideas where i'm
getting it wrong - i thought i'd demonstrate how the whole automate-ie-
from-vba thing works on a web site that we both should have access to
- www.yahoo.com and hopefully it would help you fix the code and see
what's wrong with it as i currently struggle to figure that out.

So, this is pretty much the same code as for your site (the structure
and principles) just it's a public url.

Sub Test()

'Check this out: http://www.mrexcel.com/forum/showthread.php?t=302438

Dim ie As SHDocVw.InternetExplorer
Dim varHTML As MSHTML.HTMLDocument

Set ie = New SHDocVw.InternetExplorer
With ie
.Visible = True
.Navigate "www.yahoo.com" 'Check out Yahoo site

'wait until IE finished loading the page
Do Until Not ie.Busy And ie.ReadyState = 4
DoEvents
Loop

End With

Set varHTML = ie.Document

With varHTML

.getElementById("p_13838465-p").Value = "aaa" 'Yahoo has coded
the search box _
to have an ID of 'p_13838465-p' - so grab it and set
its value to aaa
MsgBox "Check out the Browser - it should be on Yahoo and the
search box " _
& "should say 'aaa'" & vbCrLf & "Click OK only once you've
checked!", vbOKOnly

.getElementsByName("p").Item.Value = "bbb" 'The exact saem
element (yahoo search _
box) has not only ID of p_13838465-p but also a name
of "p" - so, you _
can refference the element not only by ID but also by
its name. So this _
one changes the search box to bbb

MsgBox "This time the search box " _
& "should say 'bbb'" & vbCrLf & "Click OK only once you've
checked!", vbOKOnly

.getElementById("search-submit").Click 'The yahoo page
'Search' button has id of _
'search-submit' and so you can get the element by the
id and click on it _
that's what this line of code does.

'wait until IE finished loading the page
Do Until Not ie.Busy And ie.ReadyState = 4
DoEvents
Loop

MsgBox "Check out the Browser - now it should have searched
for " _
& "'bbb'", vbOKOnly

End With

End Sub
From: MartinL on
Yes it does.

I was reading something about the .getElementById function that said that it
could be in conflict with another defined function with the same name, in
some other library, coul it be that? . . or could I redefine this function in
another way? . . .
From: MartinL on


"AB" wrote:

> if this:
>
> > If you comment out the msgbox does this:
> >
> > .getElementById("selSavedReports").Value = 932
> >
> > still fire the run-time error?
>
> still doesn't work and because i'm running out of ideas where i'm
> getting it wrong - i thought i'd demonstrate how the whole automate-ie-
> from-vba thing works on a web site that we both should have access to
> - www.yahoo.com and hopefully it would help you fix the code and see
> what's wrong with it as i currently struggle to figure that out.
>
> So, this is pretty much the same code as for your site (the structure
> and principles) just it's a public url.
>
> Sub Test()
>
> 'Check this out: http://www.mrexcel.com/forum/showthread.php?t=302438
>
> Dim ie As SHDocVw.InternetExplorer
> Dim varHTML As MSHTML.HTMLDocument
>
> Set ie = New SHDocVw.InternetExplorer
> With ie
> .Visible = True
> .Navigate "www.yahoo.com" 'Check out Yahoo site
>
> 'wait until IE finished loading the page
> Do Until Not ie.Busy And ie.ReadyState = 4
> DoEvents
> Loop
>
> End With
>
> Set varHTML = ie.Document
>
> With varHTML
>
> .getElementById("p_13838465-p").Value = "aaa" 'Yahoo has coded
> the search box _
> to have an ID of 'p_13838465-p' - so grab it and set
> its value to aaa
> MsgBox "Check out the Browser - it should be on Yahoo and the
> search box " _
> & "should say 'aaa'" & vbCrLf & "Click OK only once you've
> checked!", vbOKOnly
>
> .getElementsByName("p").Item.Value = "bbb" 'The exact saem
> element (yahoo search _
> box) has not only ID of p_13838465-p but also a name
> of "p" - so, you _
> can refference the element not only by ID but also by
> its name. So this _
> one changes the search box to bbb
>
> MsgBox "This time the search box " _
> & "should say 'bbb'" & vbCrLf & "Click OK only once you've
> checked!", vbOKOnly
>
> .getElementById("search-submit").Click 'The yahoo page
> 'Search' button has id of _
> 'search-submit' and so you can get the element by the
> id and click on it _
> that's what this line of code does.
>
> 'wait until IE finished loading the page
> Do Until Not ie.Busy And ie.ReadyState = 4
> DoEvents
> Loop
>
> MsgBox "Check out the Browser - now it should have searched
> for " _
> & "'bbb'", vbOKOnly
>
> End With
>
> End Sub
> .
>
I will have to try the Yahoo example at home, because I only have limited
internet access here at work. I was thinking that maybe it could be a
security issue because this is an internal company web site that may somehow
restrict this kind of access from VBA.