3

I am having strange issue. I am using 32 bit version IE 10. End user is using 64 bit version IE10

For me set iDoc = IE.Document works fine in below code snippet. But for end user I get "Type mismatch error".

Below is my code:

Function Run() As Integer
    Dim IE As InternetExplorer
    Dim dataCount%

    Set IE = GetIE

    Navigate IE, "http://www.my-url-here.com/index.php"
    Call Login(IE)
    IE.Quit
End Function

Private Sub Login(IE As InternetExplorer)
    Dim iDoc As HTMLDocument
    Dim uName$, pwd$
    Set iDoc = IE.Document   ' here is where it gives type mismatch error

    Call GetLoginDetails(jobBoard, uName, pwd)

    iDoc.getElementById("login").Value = uName
    iDoc.getElementById("pw").Value = pwd
    iDoc.getElementsByClassName("sub_btn")(0).Click

    Sync IE
End Sub

    Sub Sync(IE As InternetExplorer)
        Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
            Application.Wait Now + TimeSerial(0, 0, 1)
        Loop

        Do While IE.Document.ReadyState <> "complete"
            Application.Wait Now + TimeSerial(0, 0, 1)
        Loop

        'Debug.Print "Out: " & IE.Document.ReadyState
    End Sub

    Sub Navigate(IE As InternetExplorer, address$)
        IE.Navigate address
        Sync IE
    End Sub

    Function GetIE() As InternetExplorer
        Set GetIE = New InternetExplorer

        With GetIE
            .Visible = True

            .Height = 550
            .Width = 800

            .Left = Application.Width - .Width
        End With
    End Function

Please note: IE.Document.getElementById("login").Value = uName works fine for both of us.

halfer
  • 19,824
  • 17
  • 99
  • 186
TechGeek
  • 2,172
  • 15
  • 42
  • 69

1 Answers1

4

Although not specific to IE, this MS article implies that there are known issues with underlying API calls in VBA and x64 systems.

With external/custom API calls, we can accomodate for this using PtrSafe and LongPtr declarations.

Use late-binding, which I've found worked for me in the past:

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

The downside is that you will lose the feature - but IntelliSense isn't really that useful if the code doesn't run I guess...

SierraOscar
  • 17,507
  • 6
  • 40
  • 68
  • 3
    You can always early-bind to write the code (and thus get intillense) and then modify all the declarations to late-binding before releasing :) – Scott Holtzman Nov 19 '15 at 18:49
  • Thanks. That solved my issue! But I saw another issue in 64 bit operation system. GetElementsByClassName method doesn't work on iDoc (which I declared as Object now) Is this also a known issue? I am not able to install hotfix given by microsoft as I don't have admin rights on that PC but should be able to do tomorrow. – TechGeek Nov 19 '15 at 20:19
  • Not come across it personally - only thing I can think of is make sure the doc is 100% loaded before trying to access elements. Don't forget to mark as answer if it helped! (Green tick on left) – SierraOscar Nov 19 '15 at 20:20
  • Document is 100% loaded that I am sure as I am getting this error in break mode as well. Sure, will let you guys know. Thanks for help so far! – TechGeek Nov 19 '15 at 20:24