+ Reply to Thread
Results 1 to 12 of 12

compile error on code in one workbook and not the other.

Hybrid View

  1. #1
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    compile error on code in one workbook and not the other.

    Hi guys

    I had this code working in a blank workbook
    i then put it straght into another workbook and now whenever i run it it comes up with an error message saying:

    Compile error:
    User-Defined type not defined

    i dont think i did anything different
    i also copied it into a new blank workbook and it dosent work either.

    still works in the original sheet though.


    Public Sub LaunchJaguar()
        Const strURL_c As String = "https://jaguarlandrover.leapfile.net/fts/drop/jlr/portal/Login.jsp"
        Const strUsr_c As String = "[email protected]"
        Const strPwd_c As String = "xxxxxxx"
        Dim objIE As SHDocVw.InternetExplorer
        Dim ieDoc As MSHTML.HTMLDocument
        Dim tbxPwdFld As MSHTML.HTMLInputElement
        Dim tbxUsrFld As MSHTML.HTMLInputElement
        Dim btnSubmit As MSHTML.HTMLInputButtonElement
    
    '    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")  'name of the username textbox
            Set tbxUsrFld = ieDoc.all.Item("email")  'name of the password textbox
            Set btnSubmit = ieDoc.all.Item("signIn")            'name of the submit button on the form
             'Fill Fields
            tbxUsrFld.Value = strUsr_c
            tbxPwdFld.Value = strPwd_c
             'Click submit
             
            btnSubmit.Click
    objIE.Visible = True
    
    objIE.navigate "https://jaguarlandrover.leapfile.net/fts/drop/jlr/portal/Downloads.jsp"
            
             'Wait for page to load
            Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
    Err_Hnd: '(Fail gracefully)
            End Sub
    I dont like to use code i dont understand
    it makes it hard to use in other situations
    so please try to be as clear and patent as possible with me

    Criticism is welcomed

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: compile error on code in one workbook and not the other.

    At a guess you haven't added all the necessary references. Have a look at what references are in the first workbook, then select them in the second

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: compile error on code in one workbook and not the other.

    You need to ensure that any references you had enabled in the workbook that it works in are also enabled in one that you copy the code to under Tools...References in the VBA Editor.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: compile error on code in one workbook and not the other.

    ahh sorted it now thanks guys.

    i didnt realise that the enabled references where dependant on the workbook
    i thought it was set for all workbooks.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: compile error on code in one workbook and not the other.

    no problem, an alternative is to use late binding, if you're interested, have a look here

  6. #6
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: compile error on code in one workbook and not the other.

    that link dosent work bud.
    but i would be interested in that.
    anychance of a repost?
    web address is http://www.*****-clicks.com/excel/olBinding.htm

  7. #7
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: compile error on code in one workbook and not the other.

    for anyone else who is interested its
    http://www.D~I~C~K~S-clicks.com/excel/olBinding.htm
    removing ~

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: compile error on code in one workbook and not the other.

    That'd be why my link didn't work then

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: compile error on code in one workbook and not the other.

    I'd think twice about opening a website called that at home let alone in the office!!!

    Dom

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: compile error on code in one workbook and not the other.

    haha it's not mucky, I promise

  11. #11
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: compile error on code in one workbook and not the other.

    It's almost as unfortunate a name as expertsexchange.com before they twigged and added the -

    Dom

  12. #12
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: compile error on code in one workbook and not the other.

    oh my god expertsexchange.com thats classic.
    site is legit for anyone who is unsure

    and very helpful, thanks again kyle

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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