Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Refresh / Update URL
Andrew,
Sounds like Automating IE would be better: http://www.microsoft.com/mind/0898/dom.asp http://www.mvps.org/access/modules/mdl0062.htm NickHK "Andrew" wrote in message ... Hi, With help from this site I am able to open a url based on code but now I want to update the same window (ie not open another windows) of IE. How do I do that? Sub xx() ThisWorkbook.FollowHyperlink _ Address:="http://finance.yahoo.com/" Cancel = True End Sub Now I want to go to http://help.yahoo.com/help/fin/ I know I could go to the second page in one step but this is just getting the basics for some more complex coding after I get the basics. -- Andrew |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Refresh / Update URL
Hi NickHK,
I've has a look at both of those sites and the are a bit techo for me. I've copied the code into Access (I'd prefer Excel) and I'm having trouble with the CDialog beeing defined. Can we cut the code down so it basically can open a new web browser the first time and waits 10 seconds and the changes the URL in the browser to another. eg 1st www.google.com 2nd www.Yahoo.com Here's the code Private Sub Command0_Click() On Error GoTo ErrHandler Dim objShellWins As SHDocVw.ShellWindows Dim objIE As SHDocVw.InternetExplorer Dim objDoc As Object Dim i As Integer Dim strOut As String Dim intFree As Integer Dim clsDialog As Cdialog ' Wrapper around GetOpen/SaveFileName Const URL_TO_SEARCH = "http://www.mvps.org/access" Const ANCHOR_DESC_TO_SEARCH = "Comprehensive Links" ' Instantiate Set objShellWins = New SHDocVw.ShellWindows ' There might be multiple IE windows open For Each objIE In objShellWins With objIE ' Try to locate the browser with a specific address ' in it's AddressBar. You can also Navigate to a new ' address If (InStr(1, _ .LocationURL, _ URL_TO_SEARCH, vbTextCompare)) Then ' Get a reference to the HTMLDocument contained within ' the InternetExplorer instance Set objDoc = .Document If (TypeOf objDoc Is HTMLDocument) Then ' Limitations of running the following command: ' Call objIE.ExecWB( _ OLECMDID_SAVEAS, _ OLECMDEXECOPT_PROMPTUSER) ' IE's "SaveAs" dialog doesn't allow you to ' retrieve the filename the user typed in ' so use our own code for the SaveAs dialog ' The CDialog class is simply a wrapper around ' the code listed at the following URL ' http://www.mvps.org/access/api/api0001.htm ' Set clsDialog = New Cdialog With clsDialog .Hwnd = hWndAccessApp .StartDir = CurDir .ModeOpen = False .DefaultExtension = "htm" .Title = "Please select a folder to save the file" .Filter = "HTML Files (*.htm, *.html)|*.htm" strOut = .Action End With If Len(strOut) Then ' Now that we have a filename, ' Save out the HTML as a persisted file intFree = FreeFile Open strOut For Output As #intFree Write #intFree, objDoc.body.parentElement.innerHTML Close #intFree ' Alternatively, you could also just ' inpect the HTM at runtime via the property With objDoc.all For i = 1 To .Length If (TypeOf .Item(i) Is HTMLAnchorElement) Then If .Item(i).nodeName = "A" Then ' Only look for a link which has the description ' "Comprehensive Links" attached to it If (InStr(1, _ .Item(i).innerText, _ ANCHOR_DESC_TO_SEARCH, _ vbTextCompare)) Then ' Print out the URL Debug.Print objDoc.all.Item(i).href ' Bail out Exit For End If End If End If Next End With End If End If Exit For End If End With Next ExitHe On Error Resume Next Close #intFree Set clsDialog = Nothing Set objDoc = Nothing Set objIE = Nothing Set objShellWins = Nothing Exit Sub ErrHandler: With Err MsgBox "Error: " & .Number & vbCrLf & .Description, _ vbCritical Or vbOKOnly, .Source End With Resume ExitHere End Sub Thanks. -- Andrew "NickHK" wrote: Andrew, Sounds like Automating IE would be better: http://www.microsoft.com/mind/0898/dom.asp http://www.mvps.org/access/modules/mdl0062.htm NickHK "Andrew" wrote in message ... Hi, With help from this site I am able to open a url based on code but now I want to update the same window (ie not open another windows) of IE. How do I do that? Sub xx() ThisWorkbook.FollowHyperlink _ Address:="http://finance.yahoo.com/" Cancel = True End Sub Now I want to go to http://help.yahoo.com/help/fin/ I know I could go to the second page in one step but this is just getting the basics for some more complex coding after I get the basics. -- Andrew |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Refresh / Update URL
You don't need all that CDialog stuff do you.
can't you just Call UpDateIE ("www.google.com") Call UpDateIE ("www.Yahoo.com") Private function UpdateIE(argURL as string) 'Assumes you created a valid objIE object objIE.Netvigate2 argURL do until objIE.ReadyState = READYSTATE_COMPLETE 'waiting for the web page to finish loading loop end function Or you can the "MS Web Browser Control" on a userform or indeed on your worksheet. That way you contain it all in your WB. NickHK "Andrew" wrote in message ... Hi NickHK, I've has a look at both of those sites and the are a bit techo for me. I've copied the code into Access (I'd prefer Excel) and I'm having trouble with the CDialog beeing defined. Can we cut the code down so it basically can open a new web browser the first time and waits 10 seconds and the changes the URL in the browser to another. eg 1st www.google.com 2nd www.Yahoo.com Here's the code Private Sub Command0_Click() On Error GoTo ErrHandler Dim objShellWins As SHDocVw.ShellWindows Dim objIE As SHDocVw.InternetExplorer Dim objDoc As Object Dim i As Integer Dim strOut As String Dim intFree As Integer Dim clsDialog As Cdialog ' Wrapper around GetOpen/SaveFileName Const URL_TO_SEARCH = "http://www.mvps.org/access" Const ANCHOR_DESC_TO_SEARCH = "Comprehensive Links" ' Instantiate Set objShellWins = New SHDocVw.ShellWindows ' There might be multiple IE windows open For Each objIE In objShellWins With objIE ' Try to locate the browser with a specific address ' in it's AddressBar. You can also Navigate to a new ' address If (InStr(1, _ .LocationURL, _ URL_TO_SEARCH, vbTextCompare)) Then ' Get a reference to the HTMLDocument contained within ' the InternetExplorer instance Set objDoc = .Document If (TypeOf objDoc Is HTMLDocument) Then ' Limitations of running the following command: ' Call objIE.ExecWB( _ OLECMDID_SAVEAS, _ OLECMDEXECOPT_PROMPTUSER) ' IE's "SaveAs" dialog doesn't allow you to ' retrieve the filename the user typed in ' so use our own code for the SaveAs dialog ' The CDialog class is simply a wrapper around ' the code listed at the following URL ' http://www.mvps.org/access/api/api0001.htm ' Set clsDialog = New Cdialog With clsDialog .Hwnd = hWndAccessApp .StartDir = CurDir .ModeOpen = False .DefaultExtension = "htm" .Title = "Please select a folder to save the file" .Filter = "HTML Files (*.htm, *.html)|*.htm" strOut = .Action End With If Len(strOut) Then ' Now that we have a filename, ' Save out the HTML as a persisted file intFree = FreeFile Open strOut For Output As #intFree Write #intFree, objDoc.body.parentElement.innerHTML Close #intFree ' Alternatively, you could also just ' inpect the HTM at runtime via the property With objDoc.all For i = 1 To .Length If (TypeOf .Item(i) Is HTMLAnchorElement) Then If .Item(i).nodeName = "A" Then ' Only look for a link which has the description ' "Comprehensive Links" attached to it If (InStr(1, _ .Item(i).innerText, _ ANCHOR_DESC_TO_SEARCH, _ vbTextCompare)) Then ' Print out the URL Debug.Print objDoc.all.Item(i).href ' Bail out Exit For End If End If End If Next End With End If End If Exit For End If End With Next ExitHe On Error Resume Next Close #intFree Set clsDialog = Nothing Set objDoc = Nothing Set objIE = Nothing Set objShellWins = Nothing Exit Sub ErrHandler: With Err MsgBox "Error: " & .Number & vbCrLf & .Description, _ vbCritical Or vbOKOnly, .Source End With Resume ExitHere End Sub Thanks. -- Andrew "NickHK" wrote: Andrew, Sounds like Automating IE would be better: http://www.microsoft.com/mind/0898/dom.asp http://www.mvps.org/access/modules/mdl0062.htm NickHK "Andrew" wrote in message ... Hi, With help from this site I am able to open a url based on code but now I want to update the same window (ie not open another windows) of IE. How do I do that? Sub xx() ThisWorkbook.FollowHyperlink _ Address:="http://finance.yahoo.com/" Cancel = True End Sub Now I want to go to http://help.yahoo.com/help/fin/ I know I could go to the second page in one step but this is just getting the basics for some more complex coding after I get the basics. -- Andrew |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Update querytable connections and refresh data | Excel Discussion (Misc queries) | |||
Update querytable connections and refresh data | Charts and Charting in Excel | |||
Inability to start Excel after Refresh update | Excel Discussion (Misc queries) | |||
Date in cell to update upon Pivot Table refresh | Excel Programming | |||
Update cell's value without refresh screen? | Excel Programming |