cancel
Showing results for 
Search instead for 
Did you mean: 

run time error 13 type mismatch

daniel_mccollum
Active Contributor
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor

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

Answers (1)

Answers (1)

daniel_mccollum
Active Contributor

Thanks Stefan!

So simple, much appreciated 🙂