Prev: IS it possible to get the Visual Basic Form to VBA Excel
Next: fill several sheets with data from other workbooks matching criter
From: AB on 26 Mar 2010 13:01 I've never had that before but it doesn't mean that It's not the problem. Try out the Yahoo sample at home - this should give you a good understading how it works (well, you should finally see that it actually does work :)). One more suggestion, though, - maybe still try at the office this ..getElementById("selSavedReports").Value = 763'I know it's not the report you want but the first option looks somehat _ unconvincing to me in the source code. or maybe even this: ..getElementById("selSavedReports").Value = "763"'ie. string instead of Long as the goal at this point is just to finally get any element changed by vba on that site of yours. On Mar 26, 3:27 pm, MartinL <Mart...(a)discussions.microsoft.com> wrote: > 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 26 Mar 2010 18:25 AB I will try this and let you know how it went, I'm pretty sure it's may be something related to security, this is pretty straight forward. ..getElementById("selSavedReports").Value = 763 ..getElementById("selSavedReports").Value = "763" I tried both but still got the same message, sorry.
From: MartinL on 27 Mar 2010 18:20 "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 > . >
From: MartinL on 27 Mar 2010 18:25 Tried this at home, it works perfectly!!!!! why doesn't it work at work??
From: AB on 28 Mar 2010 10:25
Sorry Martin, it seems that I didn't manage to help you after all - I've been automating ie only for last couple of months myself and so i've run out of suggestions. The only last bit up my sleeve - I've had it myself when IE was always creating a new instance whenever i .navigate to a specific URL, meaning - when the code runs and creates the IE object, makes it visible - i've got 1 IE window on my screen but then I .navigate the the site i needed and that IE was (for some reason) creating new window for that site and obviously my code wasn't controlling the new window (but only the old) and therefore code couldn't find the elements i wanted it to change (as the old window didn't pull the web site - the new did). It was IE7 - so what I ended up doing was installed IE8 and it did the trick (it stopped creating the new windows). There is a method to catch the .newwindow or something like that in the shdoc - you can try googling for it. So, this seems to be the last thing i had that could be it (i.e., maybe your ie also was creating another window) but if not - i'm afraid you'll need to open up another thread or ask someone else. I hope you make it work! A. On Mar 27, 11:25 pm, MartinL <Mart...(a)discussions.microsoft.com> wrote: > Tried this at home, it works perfectly!!!!! why doesn't it work at work?? |