Search code examples
vbahp-uft

VBA code not working in UFT


I really need your help for an issue I am stucked on since 3 hours... I have a VBA code that open IE and navigate to an URL. The code seems to work when I test it within Microsoft Visual Basic :

Sub test()
    On Error Resume Next
        Set app = CreateObject("InternetExplorer.Application")
        MsgBox "OpenWindow 1 : " & Err.Number
        app.Visible = True
        app.Navigate ("salut.com")
        result = Err.Number
        MsgBox "OpenWindow 2 : " & Err.Number
    On Error GoTo 0
    If result <> 0 Then
        Call test
    End If
End Sub

This code works properly in an Excel macro but whenever I execute the exact same code in UFT (Unified Functionnal Testing) it throws errors :

  • error -2147467261 after the createObject (?)
  • error 238 after the navigate (which I think is quite normal since createObject fails)

The code is quite the same, I just pass the URL to navigate to to the function :

Function openWindow(url)
    On error resume next
        Set app = CreateObject("InternetExplorer.Application")
        app.Visible = true
        app.Navigate(url)
        result =  Err.number
    On error goto 0
    If result <> 0 Then
        openWindow (url)
    End If
End Function

I really have no idea of what the issue is...


Solution

  • I found a workaround :

    Function openWindow(urlToNavigate)
        SystemUtil.Run "iexplore.exe",urlToNavigate
    End Function