![]() |
|
|||||||
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tab Alignment in SAP SCRIPT | Mirna | SAPScript - Smartforms | 2 | 08-05-2011 09:31 PM |
| Sap gui 7.20 | macropus | SAP Manuals | 0 | 12-16-2010 03:42 AM |
| Java Script in BSP application | koko | SAP Manuals | 0 | 12-03-2010 04:14 PM |
| Stop SAP script | Pepa | SAP BASIS | 2 | 08-26-2010 01:30 PM |
| SAP Gui hangs | Golfi | SAP BASIS | 4 | 06-06-2010 03:59 PM |
| Aprenda SAP! |
|
|
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
until now I usually asked users to log - in into SAP first and then use some Excel macros to download /modify data in SAP. I have now found a neat way of opening SAP by opening a SAP shortcut - which works like a charm. Unfortunately that Charm has a very limited life span - because you are only able to run the macro once. If I want to rerun the macro I receive a Runtimeerror 91: wscript.ConnectObject Session, "on" . This is the code I am using: Code:
Dim SapApplication, SapGuiAuto, Connection, Session, wscript As Object
Public System As String
Sub SAP_prepare_sapscript()
System = "PL1"
Application.EnableCancelKey = xlDisabled
PathStrg = "C:\Temp\"
On Error Resume Next
Shell ("C:\Program Files\SAP\FrontEnd\SAPgui\"sapshcut.exe " & PathStrg & System & ".sap")
If Wait_for_Window("SAP Easy Access") = False Then GoTo giveUp 'Separate Macro which waits until SAP is open
On Error GoTo 0
If Not IsObject(SapApplication) Then
On Error Resume Next
Set SapGuiAuto = GetObject("SAPGUI")
If Err.Number 0 Then
MsgBox ("Not able to log in")
NoSap = True
Err.Clear
GoTo giveUp
End If
Set SapApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SapApplication.Children(0)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
If IsObject(wscript) Then
wscript.ConnectObject Session, "on"
wscript.ConnectObject Application, "on"
End If
Err.Clear
Session.findById("wnd[0]").maximize
run_Sap_Script
Application.ScreenUpdating = False
If Err.Number 0 Then
If Err.Number 91 Then
If Err.Number 9 Then
MsgBox ("There was an error running the Script")
Sapok = False
Err.Clear
GoTo giveUp
End If
End If
Err.Clear
End If
giveUp:
Application.WindowState = xlMaximized
End Sub
Sub run_Sap_Script()
'here I am running my normal SAP commands like opening transactions....
'log out of SAP
Session.findById("wnd[0]/tbar[0]/btn[15]").press
Session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
Err.Clear
End Sub
Any Idea what needs to be changed? Thanks for your help ERP |
| Sponsors |
|
#2
|
|||
|
|||
|
Hi ERP,
There is no right answer, but to make it run the code, it would also help. Code:
on error resume next
If IsObject(wscript) Then
wscript.ConnectObject Session, "on"
wscript.ConnectObject Application, "on"
End If
on error goto 0
Regards, Portal |
|
#3
|
|||
|
|||
|
Hi ERP,
I know the Problem ... Usually it gets me everytime I want to restart a Macro when i've changed som lines for the first time... Found out that it is better to Logon with a new Window / Logon This can be done by using this code: Code:
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("SYSTEM", True)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "PL1"
Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = inputbox("Benutzer")
Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = inputBox("Passwort")
Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "DE"
Session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus
Session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2
Session.findById("wnd[0]").sendVKey 0
This always works. Regards, Mirna |
| Entre a los Links relacionados |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|