• Answer – Gurus – WebBrowser.Navigate (Office XP)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Answer – Gurus – WebBrowser.Navigate (Office XP)

    Author
    Topic
    #410899

    What is the exact code you use the next time around? Switching to a different URL worked without problem in a quick test I did.

    Viewing 3 reply threads
    Author
    Replies
    • #886945

      Hans,

      please test inside Word XP, Windows XP SP2.

      URL’s were on a server. Thus the URL will be something like this:

      sURL = “C:Documents and Settingsusermyfile1.htm”

      and for example:

      sURL = “C:Documents and Settingsusermyfile2.htm”

      Thus on navigate the code will be:

      myWebbrowser.Navigate sURL

      and obviously flick to the second URL on a “click” event – the click event

      I just can’t understand why the second URL errors out…? for me that is.

      I will now create 2 files with “Helloworld_1” text and “Helloworld_2” text inside “.htm” file extensions.

      Thanks

      Pete

      • #886949

        I am using Word 2002 SP3 on Windows XP Pro SP2. I tried this with some existing .htm files, and had no problem switching between them. If I specified the name of a non-existent file, the standard “The page cannot be displayed” message was shown inside the browser control itself, I didn’t get an error message.

        I have also searched the Microsoft newsgroups, but I couldn’t find anything relevant.

        • #886951

          Hans,

          firstly thanks for the replies.

          Refer attached.

          Steps:

          1. Templates folder loads and I select a template to view the relevant Help documents.

          On this “first” pass evwerything is great – no problems

          2. Go back to the list of Templates and select a second “different” template.

          Choose Help – browser looks for new file and the error occurs !

          My examlpe of looking for “HelloWorld_1” and “_2” worked fine ! can you believe it.

          But following the above steps bombs !

          Thanks

          Pete

          • #886953

            I have now changed the code to be run from a button and I get this message.

            Automation error
            Unspecified error

            Pete

          • #886954

            I have now changed the code to be run from a button and I get this message.

            Automation error
            Unspecified error

            Pete

          • #886955

            I don’t see an attachment. It should be below 100 KB, and you must specify it just before posting – previewing your post will clear the attachment box.

          • #886956

            I don’t see an attachment. It should be below 100 KB, and you must specify it just before posting – previewing your post will clear the attachment box.

          • #886963

            If it does work with the simple .htm files you created, there might be a problem with the file you tried originally. What happens if you temporarily replace

            CONST_DIR & Me.lstHelpFiles.Value & “.htm”

            with a constant string containing the path and filename of one of the help files?

            • #886994

              Hans,

              this is the interesting thing to remember.

              1. on the first pass ALL URL’s load properly….

              2. 2nd pass – any URL fails !

              I then have tried the string in the “start/run” and no problems. So the pathing is correct.

              This is why I am so at a loss !

              Thanks

              Pete

            • #886997

              For the moment, I’m stumped. Could you post (a copy of) the document with the userform? Remove sensitive or proprietary information and zip the file if it is too large. This would enable Loungers to look at the problem directly.

            • #886998

              For the moment, I’m stumped. Could you post (a copy of) the document with the userform? Remove sensitive or proprietary information and zip the file if it is too large. This would enable Loungers to look at the problem directly.

            • #886999

              Have you tried using the Navigate2 method?

            • #887000

              Have you tried using the Navigate2 method?

            • #887163

              Can you test your application on a machine that does not have the Windows XP SP2 update installed? Some security changes were made, as you know, but problems they cause may be difficult to isolate without testing on SP1.

            • #887219

              Good morning from Sydney,

              1. navigate2 is no different from Navigate as per MSDN ?, but you never know – I will try it

              2. Windows XP SP2 – unfortunatley all of our work PC’s have been service packed. I tried on Office 2003 and Win XP SP 2 and the same result.

              The interesting thing with this WebBrowser control is the need to make the control invisible and then visible for it to work properly.

              I have zipped my form and will post now.

              Please note that I have commented out my listbox control code and now launch from a “test” commandbutton.

              I still think it is a Visible/ invisible flag.

              What I am going to do is make the form bigger for testing purposes and put all controls on the one page and not use a multipage control.

              Thanks for all your help

              Peter

            • #887231

              You don’t believe in making it easy for us, do you? The code behind the form refers to at least one class module that is not included in your zip file, so I can’t test it. By the time I strip out most of it, and just use the command buttons to open different files into the web browser control, it works OK. shrug

            • #887237

              Sorry Hans about the class file.

              The problem herein lies when changing from the Page 1 to Page 2 in the multi-page control.

              Did you try and load different URL’s after changing pages ? – the WebBrowser shouldn’t work if my theory is correct.

              1. Load first URL

              2. move back to Page 1 of the MultiPage and choose a different URL

              3. Choose the Help page and view the 2nd URL – this is when teh WebBrowser “should” error.

              Thanks

              Pete

            • #887253

              Yes, I see that, and I don’t know a workaround. I thought it might be a timing problem, but a test ruled that out. It might be worth while to look for third-party controls to replace Microsoft’s webbrowser control and/or multipage control.

            • #887257

              Hans,

              one more time – sorry but just to confirm.

              Did your test of moving between the multi-page and the 2nd URL also cause an error for you ?

              Thanks

              Pete

            • #887261

              Yes, I do get the “Method Navigate … Failed” error. In fact, the entire webbrowser control seems to disappear when you switch to the first tab and back.

            • #887295

              Answer:

              you can NOT use a WebBrowser control on a MultiPage control – and that’s it !

              Workaround: they are bad but this is the only answer.

              1. Minimise the MultiPage control to a height say 17. This makes the user think they are working on a multi page but they are not ! yes, you do not get the good looking layered and edging effect.

              2. Layer your controls over each other and make them visible / invisible depening upon what they click.

              In other words bring to the webbrowser control to the front when needs be and make sure it can hide behind another control in the meantime.

              Then the you will have no erros when navigating to new URL’s.

              Pete

            • #887296

              Answer:

              you can NOT use a WebBrowser control on a MultiPage control – and that’s it !

              Workaround: they are bad but this is the only answer.

              1. Minimise the MultiPage control to a height say 17. This makes the user think they are working on a multi page but they are not ! yes, you do not get the good looking layered and edging effect.

              2. Layer your controls over each other and make them visible / invisible depening upon what they click.

              In other words bring to the webbrowser control to the front when needs be and make sure it can hide behind another control in the meantime.

              Then the you will have no erros when navigating to new URL’s.

              Pete

            • #887262

              Yes, I do get the “Method Navigate … Failed” error. In fact, the entire webbrowser control seems to disappear when you switch to the first tab and back.

            • #887258

              Hans,

              one more time – sorry but just to confirm.

              Did your test of moving between the multi-page and the 2nd URL also cause an error for you ?

              Thanks

              Pete

            • #887254

              Yes, I see that, and I don’t know a workaround. I thought it might be a timing problem, but a test ruled that out. It might be worth while to look for third-party controls to replace Microsoft’s webbrowser control and/or multipage control.

            • #887259

              This is beginning to sound like a problem I ran into back in August 2003. I don’t remember whether I posted about it, but I found my test form. My problem was that when I switched to the second tab, which was going to list information about forms on the page, and then switched back to the first tab, the webbrowser control was no longer there. The control’s .LocationURL was blank… I tried repainting, I tried a bunch of things. Eventually, I just gave up because it wasn’t a really critical experiment. I figured someday I would try again using pure VB or a different host.

            • #887260

              This is beginning to sound like a problem I ran into back in August 2003. I don’t remember whether I posted about it, but I found my test form. My problem was that when I switched to the second tab, which was going to list information about forms on the page, and then switched back to the first tab, the webbrowser control was no longer there. The control’s .LocationURL was blank… I tried repainting, I tried a bunch of things. Eventually, I just gave up because it wasn’t a really critical experiment. I figured someday I would try again using pure VB or a different host.

            • #887238

              Sorry Hans about the class file.

              The problem herein lies when changing from the Page 1 to Page 2 in the multi-page control.

              Did you try and load different URL’s after changing pages ? – the WebBrowser shouldn’t work if my theory is correct.

              1. Load first URL

              2. move back to Page 1 of the MultiPage and choose a different URL

              3. Choose the Help page and view the 2nd URL – this is when teh WebBrowser “should” error.

              Thanks

              Pete

            • #887232

              You don’t believe in making it easy for us, do you? The code behind the form refers to at least one class module that is not included in your zip file, so I can’t test it. By the time I strip out most of it, and just use the command buttons to open different files into the web browser control, it works OK. shrug

            • #887220

              Good morning from Sydney,

              1. navigate2 is no different from Navigate as per MSDN ?, but you never know – I will try it

              2. Windows XP SP2 – unfortunatley all of our work PC’s have been service packed. I tried on Office 2003 and Win XP SP 2 and the same result.

              The interesting thing with this WebBrowser control is the need to make the control invisible and then visible for it to work properly.

              I have zipped my form and will post now.

              Please note that I have commented out my listbox control code and now launch from a “test” commandbutton.

              I still think it is a Visible/ invisible flag.

              What I am going to do is make the form bigger for testing purposes and put all controls on the one page and not use a multipage control.

              Thanks for all your help

              Peter

            • #887164

              Can you test your application on a machine that does not have the Windows XP SP2 update installed? Some security changes were made, as you know, but problems they cause may be difficult to isolate without testing on SP1.

            • #887227

              Some answers:

              1. I placed all of my controls onto a single – I removed the multipage control

              Thus what I had thought – re. the visible state of the WebBrowser control was at fault.

              NOw all my code works.

              BUT, BUT I want and need a multipgae control otherwise my form looks stupid as it is very cluttered.

              Any ideas gurus?

              Thanks

              Pete

            • #887228

              Some answers:

              1. I placed all of my controls onto a single – I removed the multipage control

              Thus what I had thought – re. the visible state of the WebBrowser control was at fault.

              NOw all my code works.

              BUT, BUT I want and need a multipgae control otherwise my form looks stupid as it is very cluttered.

              Any ideas gurus?

              Thanks

              Pete

            • #886995

              Hans,

              this is the interesting thing to remember.

              1. on the first pass ALL URL’s load properly….

              2. 2nd pass – any URL fails !

              I then have tried the string in the “start/run” and no problems. So the pathing is correct.

              This is why I am so at a loss !

              Thanks

              Pete

          • #886964

            If it does work with the simple .htm files you created, there might be a problem with the file you tried originally. What happens if you temporarily replace

            CONST_DIR & Me.lstHelpFiles.Value & “.htm”

            with a constant string containing the path and filename of one of the help files?

        • #886952

          Hans,

          firstly thanks for the replies.

          Refer attached.

          Steps:

          1. Templates folder loads and I select a template to view the relevant Help documents.

          On this “first” pass evwerything is great – no problems

          2. Go back to the list of Templates and select a second “different” template.

          Choose Help – browser looks for new file and the error occurs !

          My examlpe of looking for “HelloWorld_1” and “_2” worked fine ! can you believe it.

          But following the above steps bombs !

          Thanks

          Pete

      • #886950

        I am using Word 2002 SP3 on Windows XP Pro SP2. I tried this with some existing .htm files, and had no problem switching between them. If I specified the name of a non-existent file, the standard “The page cannot be displayed” message was shown inside the browser control itself, I didn’t get an error message.

        I have also searched the Microsoft newsgroups, but I couldn’t find anything relevant.

    • #886946

      Hans,

      please test inside Word XP, Windows XP SP2.

      URL’s were on a server. Thus the URL will be something like this:

      sURL = “C:Documents and Settingsusermyfile1.htm”

      and for example:

      sURL = “C:Documents and Settingsusermyfile2.htm”

      Thus on navigate the code will be:

      myWebbrowser.Navigate sURL

      and obviously flick to the second URL on a “click” event – the click event

      I just can’t understand why the second URL errors out…? for me that is.

      I will now create 2 files with “Helloworld_1” text and “Helloworld_2” text inside “.htm” file extensions.

      Thanks

      Pete

    • #886939

      Method ‘Navigate’ of object ‘IWebBrowser2’ failed

      Afternoon,

      I am using the webbrowser control on a form.

      – yes, I have searched extensively on Google

      1. set the URL for example:

      Me.WebBrowser.Navigate “about:blank”

      2. problem arises when I change the path the next time around. Fo rexample on the “click” event of a button.

      I receive the following error:
      Method ‘Navigate’ of object ‘IWebBrowser2’ failed

      Any ideas?

      Thanks

      Pete

      • #886947

        Sub ShowURL()

        On Error GoTo ErrorHandler

        If Me.WebBrowser.ReadyState = READYSTATE_COMPLETE Then
        ‘READYSTATE_UNINITIALIZED = 0,
        ‘READYSTATE_LOADING = 1,
        ‘READYSTATE_LOADED = 2,
        ‘READYSTATE_INTERACTIVE = 3,
        ‘READYSTATE_COMPLETE = 4

        Me.WebBrowser.Navigate CONST_DIR & Me.lstHelpFiles.Value & “.htm”

        lblUpdate.Caption = Me.lstHelpFiles.Value
        End If
        ‘ reset error handler to default

        Exit Sub
        ErrorHandler:
        ‘only writing to the debug window due to error problems – will delete when running perfectly
        Debug.Print Err.Description
        End Sub

      • #886948

        Sub ShowURL()

        On Error GoTo ErrorHandler

        If Me.WebBrowser.ReadyState = READYSTATE_COMPLETE Then
        ‘READYSTATE_UNINITIALIZED = 0,
        ‘READYSTATE_LOADING = 1,
        ‘READYSTATE_LOADED = 2,
        ‘READYSTATE_INTERACTIVE = 3,
        ‘READYSTATE_COMPLETE = 4

        Me.WebBrowser.Navigate CONST_DIR & Me.lstHelpFiles.Value & “.htm”

        lblUpdate.Caption = Me.lstHelpFiles.Value
        End If
        ‘ reset error handler to default

        Exit Sub
        ErrorHandler:
        ‘only writing to the debug window due to error problems – will delete when running perfectly
        Debug.Print Err.Description
        End Sub

    • #886940

      Method ‘Navigate’ of object ‘IWebBrowser2’ failed

      Afternoon,

      I am using the webbrowser control on a form.

      – yes, I have searched extensively on Google

      1. set the URL for example:

      Me.WebBrowser.Navigate “about:blank”

      2. problem arises when I change the path the next time around. Fo rexample on the “click” event of a button.

      I receive the following error:
      Method ‘Navigate’ of object ‘IWebBrowser2’ failed

      Any ideas?

      Thanks

      Pete

    Viewing 3 reply threads
    Reply To: Answer – Gurus – WebBrowser.Navigate (Office XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: