+ Reply to Thread
Results 1 to 11 of 11

Logged into Website But Can;t Navigate to Other Pages

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Logged into Website But Can;t Navigate to Other Pages

    Hi,

    I have the below which logs me into the website I want succesfully. However, once I am logged in I want to navigate to another page to which I have provided the link for. However, the macro just sits on the page you get after I log in. Have I done something wrong in the code?

    Public Sub Launch1()
    
    Dim ieApp As InternetExplorer
    Set ieApp = New InternetExplorer
    
        Const strURL_c As String = "http://www.entermywebsitehere.com"
        Const strUsr_c As String = "entermyusernamehere"
        Const strPwd_c As String = "entermypasswordhere"
        Dim objIE As SHDocVw.InternetExplorer
        Dim ieDoc As MSHTML.HTMLDocument
        Dim tbxPwdFld As MSHTML.HTMLInputElement
        Dim tbxUsrFld As MSHTML.HTMLInputElement
        Dim btnSubmit As MSHTML.HTMLInputElement
        On Error GoTo Err_Hnd
    
         'Create Internet Explorer Object
        Set objIE = New SHDocVw.InternetExplorer
    
         'Navigate the URL
        objIE.navigate strURL_c
    
         'Wait for page to load
        Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
    
             'Get document object
            Set ieDoc = objIE.document
    
             'Get username/password fields and submit button.
            Set tbxPwdFld = ieDoc.all.Item("password")
            Set tbxUsrFld = ieDoc.all.Item("username")
            Set btnSubmit = ieDoc.all.Item("OK")
    
             'Fill Fields
            tbxUsrFld.Value = strUsr_c
            tbxPwdFld.Value = strPwd_c
    
             'Click submit
            btnSubmit.Click
    
             'Wait for page to load
            Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
            Err_Hnd: '(Fail gracefully)
              objIE.Visible = True            
                
                
           
           'now that we’re in, go to the page we want (the thing is my macro doesnt seem to run this bit)
        ieApp.navigate "https://www.entermywebsitehere.com/nextpage/SystemMain.php?page=mon&spid=1&realcategoryid=31&tou33"
       Do While ieApp.Busy: DoEvents: Loop
      Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
                 
            End Sub

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Logged into Website But Can;t Navigate to Other Pages

    try changing
    ieApp.navigate

    to
    objIE.navigate
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Logged into Website But Can;t Navigate to Other Pages

    Thanks Sean but still not working. Another way would be to open a new tab and browse to the url. Is that possible?

  4. #4
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Logged into Website But Can;t Navigate to Other Pages

    i usually use something like this after btnSubmit.Click


        Do While objIE.Busy: DoEvents: Loop
        Do Until objIE.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
       
        'now that we’re in, go to the page we want
        objIE.Navigate "http://severe-frost-552.heroku.com/"
        Do While objIE.Busy: DoEvents: Loop
        Do Until objIE.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

    this code basically waits until the page is fully loaded after submitting your username etc to allow the page to log you in.
    Then it redirects the IE to your next page
    then it waits until it is fully loaded.

    Check your website address, i couldnt even access it.

  5. #5
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Logged into Website But Can;t Navigate to Other Pages

    change this bit
    Do While ieApp.Busy: DoEvents: Loop
      Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
    to
    Do While objIE.Busy: DoEvents: Loop
        Do Until objIE.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    you havent assigned ieApp, you are using objIE

  6. #6
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Logged into Website But Can;t Navigate to Other Pages

    Or how would I change the loop's as I think that is what may be causing it. I think it might be trying to go to the page I want before fully logged in?

  7. #7
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Logged into Website But Can;t Navigate to Other Pages

    no because you wont be logged in using a new tab.
    What is actually happening?
    have you checked the code is entering your user name & password before submitting.
    If so, when you are logged in does the web page show you are logged in?

  8. #8
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Logged into Website But Can;t Navigate to Other Pages

    Yep, I've checked and it is entering my username and password and logging me in fine.

    If I remove

       'now that we’re in, go to the page we want (the thing is my macro doesnt seem to run this bit)
        objIE.navigate "https://www.entermywebsitehere.com/nextpage/SystemMain.php?page=mon&spid=1&realcategoryid=31&tou33"
       Do While ieApp.Busy: DoEvents: Loop
      Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
    then everything works as should be. But I obviously need this bit to now go to the page that I want since I am logged in.

  9. #9
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Logged into Website But Can;t Navigate to Other Pages

    Thanks, have it working now.

    Last thing....how do I then copy the entire page that loads and paste it into my excel workbook?

  10. #10
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Logged into Website But Can;t Navigate to Other Pages

    I've searched around and came across this, but it doesn't work

    ie.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
    ie.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
    ie.Quit
    
    Range("A1").Select
    ActiveSheet.Paste

  11. #11
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Logged into Website But Can;t Navigate to Other Pages

    try something like this

    Dim MyDoc as object
    
    
     'Get document object
    Set MyDoc = objIE.document
    sheet1.range("A1").value = MyDoc.Body.Innertext

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 12-07-2014, 08:33 PM
  2. Pull data from multiple pages on same website
    By willhutton93 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-10-2014, 03:15 PM
  3. Replies: 1
    Last Post: 01-12-2011, 07:28 PM
  4. Create form to navigate report pages
    By usafmeinweg in forum Access Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2010, 06:22 PM
  5. How can I navigate throw multiple Web pages...
    By Luc Dansereau in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-15-2005, 07:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1