From: Michael Bednarek on 16 May 2007 07:35 On 15 May 2007 15:28:43 -0700, Ed wrote in microsoft.public.word.vba.general: [snip] >I have > >Sub Try_IE() > >Dim objIE >Set objIE = CreateObject("InternetExplorer.Application") >objIE.Visible = True > >End Sub > >It opens a brand-new blank IE page with no URL. I can't see how to >set an object to the currently displayed web page. I don't want to >navigate to a page - I need to work with the web page already open. >What am I missing? You asked the same question in the newsgroup "microsoft.public.scripting.vbscript" under the the thread "Use script to navigate web page?" (Message-ID: <1178733093.797260.206820(a)y80g2000hsf.googlegroups.com>); the answers there seem quite competent. For a third-party solution, you could look at <http://www.iopus.com/imacros/>; there may be others. -- Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
From: Ed on 16 May 2007 09:59 > You asked the same question in the newsgroup > "microsoft.public.scripting.vbscript" under the the thread "Use script > to navigate web page?" (Message-ID: > <1178733093.797260.206...(a)y80g2000hsf.googlegroups.com>); the answers > there seem quite competent. Yes, Michael, I did. I understand Word macros much better than I do scripting, and knew different people frequent the two NG. I had no idea this would be such an uncommon task - I thought there would be tons of sample code already there. Also, the VBA code answer in the Scripting group was not there until I looked this morning, and I have not been able to try it yet. I apologize if I have offended the proprieties of the newsgroups. Ed
From: Ed on 17 May 2007 11:02 With many thanks to all who have responded in both the Word VBA and the Scripting newgroups (and with apologies for not having included both groups from the beginning, because now I don't know how to join the two threads!), I have a Word VBA macro that allows me to open an instance of IE, browse to the page I need, and read information from the page. What I can not do, though, is find and activate the two controls I need. I want to find and check a checkbox, and then find and activate the Next page link. I tried using SendKeys, but it didn't work - I think perhaps because I was stepping through the macro and the web page didn't have the focus. If anyone would like to point me in the right direction, your further help is greatly appreciated. Ed Sub Try_IE() Dim objIE Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True 'fmDoIE.Show If MsgBox("Do you want to continue?", vbYesNo) = vbNo Then objIE.Quit Set objIE = Nothing Exit Sub End If 'MsgBox objIE.LocationURL Dim objIE2 Set objIE2 = GetIE(objIE.LocationURL) Dim docIE Set docIE = objIE2.Document 'Get each line of the web page into an array Dim PageArray PageArray = Split(docIE.Body.InnerHTML, Chr(13)) Dim objDoc As Document Dim docRng As Range Dim parRng As Range Set objDoc = Documents.Open("C:\Documents and Settings\edward.millis \Desktop\TestMe.doc") Set docRng = objDoc.Content Dim x As Long, y As Long, z As Long x = UBound(PageArray) Stop For z = 0 To x y = docRng.Paragraphs.Count Set parRng = objDoc.Paragraphs(y).Range parRng.Text = PageArray(z) & Chr(13) Next z Set parRng = objDoc.Paragraphs(docRng.Paragraphs.Count).Range parRng.Text = "^p" & "^p" & "^p" Set parRng = objDoc.Paragraphs(docRng.Paragraphs.Count).Range Stop On Error GoTo EndLoop Dim frmIE For Each frmIE In docIE.Forms parRng.Text = "Name:= " & frmIE.Name & "; " & "ID:= " & frmIE.ID & vbCrLf Set parRng = objDoc.Paragraphs(docRng.Paragraphs.Count).Range Next frmIE EndLoop: On Error GoTo 0 'objIE2.Activate SendKeys "^F", Wait SendKeys "Clear checkboxes", Wait SendKeys "{ENTER}", Wait SendKeys "{ESC}", Wait SendKeys "{TAB}", Wait SendKeys " ", Wait Stop Set objIE = Nothing Set objIE2 = Nothing Set docIE = Nothing 'objDoc.Close wdDoNotSaveChanges End Sub '******************************************* ' huge thanks to Tim Williams for this function! 'Find an IE window with matching location ' Assumes no frames. Function GetIE(sAddress As String) As Object Dim objShell As Object, objShellWindows As Object, o As Object Dim retVal As Object, sURL As String Set retVal = Nothing Set objShell = CreateObject("Shell.Application") Set objShellWindows = objShell.Windows 'see if IE is already open For Each o In objShellWindows sURL = "" On Error Resume Next sURL = o.Document.Location On Error GoTo 0 If sURL <> "" Then If sURL Like sAddress & "*" Then Set retVal = o Exit For End If End If Next o Set GetIE = retVal End Function
From: Michael Bednarek on 19 May 2007 01:56 On 17 May 2007 08:02:35 -0700, Ed wrote in microsoft.public.word.vba.general: >With many thanks to all who have responded in both the Word VBA and >the Scripting newgroups (and with apologies for not having included >both groups from the beginning, because now I don't know how to join >the two threads!), I have a Word VBA macro that allows me to open an >instance of IE, browse to the page I need, and read information from >the page. What I can not do, though, is find and activate the two >controls I need. I want to find and check a checkbox, and then find >and activate the Next page link. I tried using SendKeys, but it >didn't work - I think perhaps because I was stepping through the macro >and the web page didn't have the focus. If anyone would like to point >me in the right direction, your further help is greatly appreciated. [snip] To find the name of forms and other elements you have to inspect the site's HTML code; the "Internet Explorer Developer Toolbar" can also help; see: <http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en> which points to <http://download.microsoft.com/download/f/3/c/f3c93e70-ccdc-46c9-bbd4-70d94bdd0cc9/IEDevToolBarSetup.msi>. -- Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
From: Ed on 19 May 2007 09:48 On May 18, 10:56 pm, Michael Bednarek <mbATmbednarek....(a)BLACKHOLESPAM.NET> wrote: > To find the name of forms and other elements you have to inspect the > site's HTML code; the "Internet Explorer Developer Toolbar" can also > help; see: > <http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672...> > which points to > <http://download.microsoft.com/download/f/3/c/f3c93e70-ccdc-46c9-bbd4-...>. > Thanks, Michael. I greatly appreciate your coming back to this. Unfortunately, all this is being done at work kind of as a side issue, and I do not have permissions to install anything, especially programming tools. The lines Dim PageArray PageArray = Split(docIE.Body.InnerHTML, Chr(13)) seem to do a fairly decent job of reading the page's HTML code - as far as I know, that is. I once made a personal web page using FrontPage, and that's the full extent of my HTML experience! So I really don't know what I'm looking for, how to get a handle on it once I identify it, or what I need to do with it once I find it. It's probably comparable to the 5-year-old who thinks all you do to drive a car is move the steering wheel back and forth. I just need to mark a checkbox, then go to the next page and mark the same checkbox, lather, rinse and repat until I run out of pages. I don't want to become an expert IE programmer - heck, I'm not a programmer at all! I probably don't understand the depth of what I'm asking for, which I do know can be frustrating to those trying to help me. If this is something that is probably beyond my limited understanding without a grest deal more in-depth training, then I'm sure you have more important and interesting things to do that will be mre fruitful. I do thank you for all the time and help you have given me. Ed
First
|
Prev
|
Pages: 1 2 Prev: How to start Word without templates through VB 6.0 Next: InlineShapes.AddPicture |