SAP GUI脚本(循环,参考变量)VBA中没有背景,请帮助

2020-09-06 05:23发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


大家好,我在这里搜索了多个线程,但是由于我没有VBA的背景知识,因此很难理解它们。 我真的很感谢任何人都可以提供帮助。 这段代码应该可以帮助我将粘贴一系列单元格从Excel复制到SAP。 遇到的问题:

1)我正在尝试设置session.findbyid部分(" [ 0 ,0]")或(" [ 0 ,3]")等。 此粗体0(我假设是SAP中的行位置,移至下一行),即我尝试创建一个循环,而不是[0,0] [1,0] [2,0]。 我已经尝试过此方法 https://通过使用此" Cstr"来answer.sap.com/questions/5701329/referencing-a-variable-in-session-findbyid-command.html ,但无效。

2)我也在尝试循环此objSheet.Cells( 10 ,1)行

我在线程中找到的一些代码如下,但它也不起作用

Dim objSheet,intRow,行

对于行= 10

行=行+ 1

下一行

这是我当前的代码,其中包含SAP连接代码以及我从此处的线程复制的对Excel的代码引用。

昏暗会话

设置SapGuiAuto = GetObject(" SAPGUI")

设置SetApp = SapGuiAuto.GetScriptingEngine

设置连接= SetApp.Children(0)

设置会话= Connection.Children(0)

Session.findById(" wnd [0]")。maximize

设置objSheet = ActiveWorkbook.Sheets(2)

Session.findById(" wnd [0]/tbar [0]/okcd")。Text ="/img/nf-65"

Session.findById(" wnd [0]")。sendVKey 0

Session.findById(" wnd [0]/usr/ctxtBKPF-BLDAT")。Text = objSheet.Cells(3,2)

Session.findById(" wnd [0]/usr/ctxtBKPF-BUDAT")。Text = objSheet.Cells(3,2)

Session.findById(" wnd [0]/usr/ctxtBKPF-BUKRS")。Text = objSheet.Cells(4,2)

Session.findById(" wnd [0]/usr/txtBKPF-MONAT")。Text = objSheet.Cells(5,2)

Session.findById(" wnd [0]/usr/ctxtBKPF-WAERS")。Text = objSheet.Cells(6,2)

Session.findById(" wnd [0]/usr/ctxtBKPF-WAERS")。SetFocus

Session.findById(" wnd [0]/usr/ctxtBKPF-WAERS")。caretPosition = 3

Session.findById(" wnd [0]/tbar [1]/btn [20]")。按

Session.findById(" wnd [0]/mbar/menu [4]/menu [0]")。选择Session.findById(" wnd [1]/usr/sub:SAPLF034:1100/txtT021G-LTEXT [ 3,11]")。SetFocus Session.findById(" wnd [1]/usr/sub:SAPLF034:1100/txtT021G-LTEXT [3,11]")。caretPosition = 5 Session.findById(" wnd [1]" ).sendVKey 2

Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-BSCHL [0,0]")。Text = objSheet.Cells(10,1)

Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtRF05V-KONTO [0,3]")。Text = objSheet.Cells(10,2)Session.findById(" wnd [0 ]/usr/sub:SAPLF040:8003/txtBSEG-WRBTR [0,14]")。Text = objSheet.Cells(10,3)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG -KOSTL [0,31]")。Text = objSheet.Cells(10,4)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-SGTXT [0,42]")。Text = objSheet.Cells(10,5)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-BSCHL [1,0]")。Text = objSheet.Cells(11,1)会话。 findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtRF05V-KONTO [1,3]")。Text = objSheet.Cells(11,2)Session.findById(" wnd [0]/usr/sub :SAPLF040:8003/txtBSEG-WRBTR [1,14]")。Text = objSheet.Cells(11,3)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-KOSTL [1, 31]")。Text = objSheet.Cells(11,4)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-SGTXT [1,42]")。Text = objSheet.Cells( 11、5)

Session.findById(" wnd [0]/usr")。verticalScrollbar.Position = 23

Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-SGTXT [15,42]")。SetFocus Session.findById(" wnd [0]/usr/sub:SAPLF040:8003 /ctxtBSEG-SGTXT[15,42]").caretPosition = 25 Session.findById(" wnd [0]/tbar [1]/btn [14]")。按

Session.findById(" wnd [0]/usr/txtBKPF-BKTXT")。Text = objSheet.Cells(7,2)

Session.findById(" wnd [0]/usr/txtBKPF-BKTXT")。SetFocus

Session.findById(" wnd [0]/usr/txtBKPF-BKTXT")。caretPosition = 25

结束子

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


大家好,我在这里搜索了多个线程,但是由于我没有VBA的背景知识,因此很难理解它们。 我真的很感谢任何人都可以提供帮助。 这段代码应该可以帮助我将粘贴一系列单元格从Excel复制到SAP。 遇到的问题:

1)我正在尝试设置session.findbyid部分(" [ 0 ,0]")或(" [ 0 ,3]")等。 此粗体0(我假设是SAP中的行位置,移至下一行),即我尝试创建一个循环,而不是[0,0] [1,0] [2,0]。 我已经尝试过此方法 https://通过使用此" Cstr"来answer.sap.com/questions/5701329/referencing-a-variable-in-session-findbyid-command.html ,但无效。

2)我也在尝试循环此objSheet.Cells( 10 ,1)行

我在线程中找到的一些代码如下,但它也不起作用

Dim objSheet,intRow,行

对于行= 10

行=行+ 1

下一行

这是我当前的代码,其中包含SAP连接代码以及我从此处的线程复制的对Excel的代码引用。

昏暗会话

设置SapGuiAuto = GetObject(" SAPGUI")

设置SetApp = SapGuiAuto.GetScriptingEngine

设置连接= SetApp.Children(0)

设置会话= Connection.Children(0)

Session.findById(" wnd [0]")。maximize

设置objSheet = ActiveWorkbook.Sheets(2)

Session.findById(" wnd [0]/tbar [0]/okcd")。Text ="/img/nf-65"

Session.findById(" wnd [0]")。sendVKey 0

Session.findById(" wnd [0]/usr/ctxtBKPF-BLDAT")。Text = objSheet.Cells(3,2)

Session.findById(" wnd [0]/usr/ctxtBKPF-BUDAT")。Text = objSheet.Cells(3,2)

Session.findById(" wnd [0]/usr/ctxtBKPF-BUKRS")。Text = objSheet.Cells(4,2)

Session.findById(" wnd [0]/usr/txtBKPF-MONAT")。Text = objSheet.Cells(5,2)

Session.findById(" wnd [0]/usr/ctxtBKPF-WAERS")。Text = objSheet.Cells(6,2)

Session.findById(" wnd [0]/usr/ctxtBKPF-WAERS")。SetFocus

Session.findById(" wnd [0]/usr/ctxtBKPF-WAERS")。caretPosition = 3

Session.findById(" wnd [0]/tbar [1]/btn [20]")。按

Session.findById(" wnd [0]/mbar/menu [4]/menu [0]")。选择Session.findById(" wnd [1]/usr/sub:SAPLF034:1100/txtT021G-LTEXT [ 3,11]")。SetFocus Session.findById(" wnd [1]/usr/sub:SAPLF034:1100/txtT021G-LTEXT [3,11]")。caretPosition = 5 Session.findById(" wnd [1]" ).sendVKey 2

Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-BSCHL [0,0]")。Text = objSheet.Cells(10,1)

Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtRF05V-KONTO [0,3]")。Text = objSheet.Cells(10,2)Session.findById(" wnd [0 ]/usr/sub:SAPLF040:8003/txtBSEG-WRBTR [0,14]")。Text = objSheet.Cells(10,3)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG -KOSTL [0,31]")。Text = objSheet.Cells(10,4)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-SGTXT [0,42]")。Text = objSheet.Cells(10,5)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-BSCHL [1,0]")。Text = objSheet.Cells(11,1)会话。 findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtRF05V-KONTO [1,3]")。Text = objSheet.Cells(11,2)Session.findById(" wnd [0]/usr/sub :SAPLF040:8003/txtBSEG-WRBTR [1,14]")。Text = objSheet.Cells(11,3)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-KOSTL [1, 31]")。Text = objSheet.Cells(11,4)Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-SGTXT [1,42]")。Text = objSheet.Cells( 11、5)

Session.findById(" wnd [0]/usr")。verticalScrollbar.Position = 23

Session.findById(" wnd [0]/usr/sub:SAPLF040:8003/ctxtBSEG-SGTXT [15,42]")。SetFocus Session.findById(" wnd [0]/usr/sub:SAPLF040:8003 /ctxtBSEG-SGTXT[15,42]").caretPosition = 25 Session.findById(" wnd [0]/tbar [1]/btn [14]")。按

Session.findById(" wnd [0]/usr/txtBKPF-BKTXT")。Text = objSheet.Cells(7,2)

Session.findById(" wnd [0]/usr/txtBKPF-BKTXT")。SetFocus

Session.findById(" wnd [0]/usr/txtBKPF-BKTXT")。caretPosition = 25

结束子

付费偷看设置
发送
1条回答
hengyuye
1楼-- · 2020-09-06 06:09

这个

 session.findbyid部分(" [0,0]")或(" [0,3]")

等效于此

将varLoop视作整数
 对于varLoop = 1到10
 session.findbyid部分(" ["&varLoop&",0]")或(" ["&varLoop&",3]")
 下一个varLoop

 

一周热门 更多>