Skip to Content

run time error 13 type mismatch

when declaring vars in VBA such as:

Dim SAPGuiAuto As SAPFEWSELib.GuiApplication

Dim SAPConn As SAPFEWSELib.GuiConnection

Dim SAPSess As SAPFEWSELib.GuiSession

then setting them via

Set SAPGuiAuto = GetObject("SAPGUI")

or

set SAPSess = SAPConn.Sessions(0)

I get run time error '13': type mismatch

When using declarations such as

Dim SAPGuiAuto As Object

Dim SAPConn As Object

Dim SAPSess As Object

then all is well, except I lose the context of the available functions.

I've attempted a brute force approach by adding many references in excel

& trying all sorts of declarations.

any advice on specific declaration?

regards

Daniel

references.jpg (29.5 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 08, 2016 at 06:18 AM

    Hello Daniel,

    as far as I can see are your declarations not correct, try this code:

    Sub Test()
    
      Dim SAPGuiAuto As Object
      Dim SAPApp As SAPFEWSELib.GuiApplication
      Dim SAPConn As SAPFEWSELib.GuiConnection
      Dim SAPSess As SAPFEWSELib.GuiSession
    
      Stop
    
      Set SAPGuiAuto = GetObject("SAPGUI")
      Set SAPApp = SAPGuiAuto.GetScriptingEngine
    
      Set SAPConn = SAPApp.Children(0)
      Set SAPSess = SAPConn.Children(0)
    
      '...
    
    End Sub
    

    Let us know your results.

    Cheers
    Stefan

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 09, 2016 at 02:43 AM

    Thanks Stefan!

    So simple, much appreciated :)

    Add comment
    10|10000 characters needed characters exceeded