如何选择特定的SAP GUI会话? [英] How to choose specific SAP GUI session?

查看:96
本文介绍了如何选择特定的SAP GUI会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行使用SAP GUI脚本编写的Excel VBA代码.

I am trying to run an Excel VBA code which uses SAP GUI Scripting.

我在Sap进行了一些公开会议,并使用两个系统"F6P"和"FVP"同时.

I have some open sessions in Sap and using two systems "F6P" and "FVP" at the same time.

如何在"FVP"之一上运行会议?
您可以看到下面有两个会话打开
一个是F6P SAP盒子,另一个是FVP SAP盒子.

How do I run on one of the "FVP" sessions?
You can see below there are two session open
One is F6P SAP box and the other is FVP SAP box.

Option Explicit
Public SapGui, App, Connection, Session, SapGuiAuto, WScript

Sub Overconfirmation()
    Call SAP
    Call tcode
    End
    Sub SAP()
    If Not IsObject(App) Then
        Set SapGuiAuto = GetObject("SAPGUI")
        Set App = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(Connection) Then
        Set Connection = App.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 App, "on"
        Set Session = Application.ActiveSession
    End If
End Sub

Sub tcode()
    Session.findById("wnd[0]").maximize
    Session.findById("wnd[0]/tbar[0]/okcd").Text = "/n/sapapo/bopin"
    Session.findById("wnd[0]").sendVKey 0
End Sub  

推荐答案

SAP系统的ID在对象SystemName 中定义.sap.com/viewer/b47d018c3b9b45e897faf66a6c0885a8/760.01/zh-CN/15fb37a11e9143eb8eb0e5da85958422.html"rel =" nofollow noreferrer> GuiSessionInfo ,它本身就是 Info属性>对象 GuiSession 一个>.您可以使用以下代码访问所有现有的会话:

The ID of the SAP system is defined in the property SystemName of the object GuiSessionInfo, which itself is the property Info of the object GuiSession. You may access all the existing sessions with this code:

For connNr = 0 To Application.Children.Length - 1
  Set conn = Application.Children.ElementAt(connNr)
  For sessNr = 0 to conn.Children.Length - 1
    Set sess = conn.Children.ElementAt(sessNr)
    If sess.Busy = False Then
      ' Test Busy because property Info is blocked when the session runs something
      If sess.Info.SystemName = "FVP" Then
        ' Do whatever you want with session sess
      End If
    End If
  Next
Next

这篇关于如何选择特定的SAP GUI会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆