Skip to Content
0

run time error 13 type mismatch

Dec 08, 2016 at 03:53 AM

85

avatar image

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)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Stefan Schnell
Dec 08, 2016 at 06:18 AM
1

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

Share
10 |10000 characters needed characters left characters exceeded
Daniel McCollum Dec 09, 2016 at 02:43 AM
1

Thanks Stefan!

So simple, much appreciated :)

Share
10 |10000 characters needed characters left characters exceeded