on 08-11-2010 6:23 PM
Code:
<font color='green'>
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<BR> 'Are you connected to SAP?
<BR> If Not IsObject(SAPApplication) Then
<BR> Set SapGuiAuto = GetObject("SAPGUI")
<BR> Set SAPApplication = SapGuiAuto.GetScriptingEngine
<BR> End If
<BR> If Not IsObject(Connection) Then
<BR> Set Connection = SAPApplication.Children(0)
<BR> End If
<BR> If Not IsObject(Session) Then
<BR> Set Session = Connection.Children(0)
<BR> End If
<BR> If IsObject(WScript) Then
<BR> WScript.ConnectObject Session, "on"
<BR> WScript.ConnectObject SAPApplication, "on"
<BR> End If
<BR>
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<BR> 'Move to the PO rec creation screen
<BR> Session.findById("wnd[0]").Maximize
<BR> Session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme5a"
<BR> Session.findById("wnd[0]").sendVKey 0
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</font>
<BR><BR>
This works fine with the Outlook library disabled, however, once you enable it, you get Error 438 "Object doesn't support this property or method". This is very easy to recreate, as all you have to do is turn on the Microsoft Outlook library in your references.
<BR><BR>
session is apparently a property of the Outlook library, so the standard format of the code won't work. I've tried renaming session to "SAP_Session", but then I get error 91 "Object variable or With block variable not set."
<BR><BR>
I've hit an impasse because I need the outlook library to send email confirmations to everyone that my SAP data belongs to, but the SAP remote controls aren't playing nice.
<BR><BR>
Code:
<font color='green'>
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<BR> 'Are you connected to SAP?
<BR>
<BR> Dim SAP_Session As Object
<BR>
<BR> If Not IsObject(SAPApplication) Then
<BR> Set SapGuiAuto = GetObject("SAPGUI")
<BR> Set SAPApplication = SapGuiAuto.GetScriptingEngine
<BR> End If
<BR> If Not IsObject(Connection) Then
<BR> Set Connection = SAPApplication.Children(0)
<BR> End If
<BR> If Not IsObject(Session) Then
<BR> Set SAP_Session = Connection.Children(0)
<BR> End If
<BR> If IsObject(WScript) Then
<BR> WScript.ConnectObject Session, "on"
<BR> WScript.ConnectObject SAPApplication, "on"
<BR> End If
<BR>
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<BR> 'Move to the PO rec creation screen
<BR> SAP_Session.findById("wnd[0]").Maximize
<BR> SAP_Session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme5a"
<BR> SAP_Session.findById("wnd[0]").sendVKey 0
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</font>
Edited by: reddozen on Aug 11, 2010 7:30 PM
So have you tried to work with LateBinding Outlook ?
Dim objOL as Object
Set objOL = CreateObject("Outlook.Application")
btw you have an error in your code:
Dim SAP_Session As Object
If Not IsObject(SAPApplication) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPApplication.Children(0)
End If
'If Not IsObject(Session) Then '<-- here !!!
'should be like this:
If Not IsObject(SAP_Session) Then
Set SAP_Session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject SAP_Session, "on" '<- and here
WScript.ConnectObject SAPApplication, "on"
End If
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
11 years later and I see the same problem exists! Not sure what the solution really was back then as no follow up.
The same thing happens when I add the Microsoft Outlook 16.0 Object Library a Session is never created. If I remove the outlook reference it works fine.
The outlook code is on another form that the user of THIS form doesn't use so its not executed.
Since this problem was identified back in 2010 and nothing else , I'll assume its in the way this code is written.
I'm using SAP GUI Scripting API
Microsoft Outlook 16.0 Object Library
SAP version is 7.50
thanks
Peter
Session_number_max = 5 'the maximum number of possible SAP sessions
Dim session_number_(5)
On Error Resume Next
Set SapGuiAuto = GetObject("SAPGUI")
Set SAP = SapGuiAuto.GetScriptingEngine
Set Connection = SAP.Children(0)
Set session = Connection.Children(0)
'------------------------------------------- new session connect -------------------------------------------------------------
session_number_all = Connection.Children.Count - 1
If Connection.Children.Count = 0 Then
'MsgBox ("Couts =") & session_number_all
'GoTo Erreur
End If
For i = 0 To Session_number_max - 1
session_number_(i) = 0
Next
For session_number = 0 To session_number_all
Set session = Connection.Children(Int(session_number))
session_number_(session.Info.SessionNumber) = session.Info.SessionNumber
Next
If session_number_all < Session_number_max - 1 Then
Do
trycount = trycount + 1
session.CreateSession '#### this ends up in an infinite loop as CreateSession never creates a valid session. ####
'WScript.sleep 500
If Connection.Children.Count - session_number_all >= 2 Then Exit Do '#### this ends up in an infinite loop as
If trycount >5 then
exit loop
GoTo Errorcode
end if
Loop
On Error Resume Next
Error_number = 1
For session_number = 0 To session_number_all + 1
Err.Clear
Set session = Connection.Children(Int(session_number + 1))
If Err.Number > 0 Or Err.Number < 0 Then Exit For
'MsgBox (" Session = ") & session_number
If session_number_(session.Info.SessionNumber) = 0 Then
Error_number = 0
Exit For
End If
'session.findById("wnd[0]").iconify 'So you can send another SAP session in the task bar.
Next
On Error GoTo 0
Else
MsgBox "Nouvelle session pas possible!"
End If
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.