<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script MB51 in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194600#M1981127</link>
    <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;a317531&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;I mean, you're missing the "Next i" after "For" loop. Is that it?&lt;BR /&gt;Otherwise, please submit the error message, without it it's hard to say what is the issue.&lt;/P&gt;Regards,&lt;BR /&gt;Mateusz</description>
    <pubDate>Fri, 22 May 2020 06:11:17 GMT</pubDate>
    <dc:creator>MateuszAdamus</dc:creator>
    <dc:date>2020-05-22T06:11:17Z</dc:date>
    <item>
      <title>Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194599#M1981126</link>
      <description>&lt;P&gt;I'm having trouble creating a script on the MB51 screen, the code looks like this:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;Sub gerar_contagem()






Set session = GetObject("SAPGUI").GetScriptingEngine.Children(0).Children(0)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/NMB51"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/txtENAME-LOW").Text = "w890230"
session.findById("wnd[1]/usr/txtENAME-LOW").SetFocus
session.findById("wnd[1]/usr/txtENAME-LOW").caretPosition = 7
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellColumn = "TEXT"
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell
session.findById("wnd[0]/usr/ctxtBUDAT-LOW").SetFocus
session.findById("wnd[0]/usr/ctxtBUDAT-LOW").caretPosition = 0
session.findById("wnd[0]").sendVKey 4


Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(, ”Excel.Application”)
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet(1)


For i = 2 To objSheet.UsedRange.Rows.Count
G8 = Trim(CStr(objSheet.Cells(i, 7).Value)) ‘G8
I8 = Trim(CStr(objSheet.Cells(i, 7).Value)) ‘I8


session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").focusDate = G8
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/ctxtBUDAT-HIGH").SetFocus
session.findById("wnd[0]/usr/ctxtBUDAT-HIGH").caretPosition = 0
session.findById("wnd[0]").sendVKey 4
session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").focusDate = I8
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[48]").press
session.findById("wnd[0]/mbar/menu[3]/menu[2]/menu[1]").Select
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").setCurrentCell 27, "TEXT"
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").firstVisibleRow = 18
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").selectedRows = "27"
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").clickCurrentCell
session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").Select
session.findById("wnd[1]/tbar[0]/btn[11]").press




End Sub
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The problem is in these lines that have the objective of inserting the information from cells G8 and I8 of the spreadsheet in the date fields of screen MB51::&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(, ”Excel.Application”)
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet(1)


For i = 2 To objSheet.UsedRange.Rows.Count
G8 = Trim(CStr(objSheet.Cells(i, 7).Value)) ‘G8
I8 = Trim(CStr(objSheet.Cells(i, 7).Value)) ‘I8
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;could someone help me with this issue?&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 02:30:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194599#M1981126</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-05-21T02:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194600#M1981127</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;a317531&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;I mean, you're missing the "Next i" after "For" loop. Is that it?&lt;BR /&gt;Otherwise, please submit the error message, without it it's hard to say what is the issue.&lt;/P&gt;Regards,&lt;BR /&gt;Mateusz</description>
      <pubDate>Fri, 22 May 2020 06:11:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194600#M1981127</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-05-22T06:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194601#M1981128</link>
      <description>I intended to insert the cell information "G8" and "I8" from excel
for SAP field, but I can't select only this cell and end the loop (Next i)(Eu pretendo setar a informação da celula G8 e I8 do excel para o campo data da tela MB51 no SAP, mas não tenho experiência em fazer esta conexão, e também não sei finalizar o loop, pois não encontro material para estudar sobre)</description>
      <pubDate>Mon, 25 May 2020 23:46:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194601#M1981128</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-05-25T23:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194602#M1981129</link>
      <description>&lt;P&gt;The error message:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1813715-erro.jpg" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 19:30:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194602#M1981129</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-05-26T19:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194603#M1981130</link>
      <description>&lt;P&gt;Hello Alex,&lt;/P&gt;&lt;P&gt;Try searching the internet. VBA has been around for quite some time now and there is plenty of information on different forums. Your favorite search engine is your best friend in this case. &lt;/P&gt;&lt;P&gt;Also, check out the Microsoft pages about VBA: &lt;A href="https://docs.microsoft.com/en-us/office/vba/api/overview/"&gt;https://docs.microsoft.com/en-us/office/vba/api/overview/&lt;/A&gt;.&lt;/P&gt;Kind regards,&lt;BR /&gt;Mateusz</description>
      <pubDate>Tue, 26 May 2020 19:42:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194603#M1981130</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-05-26T19:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194604#M1981131</link>
      <description>&lt;P&gt;Hello Alex,&lt;/P&gt;&lt;P&gt;I would suggest putting a break point and executing the code step-by-step to find the error source. At this moment the error message is too generic.&lt;/P&gt;Kind regards,&lt;BR /&gt;Mateusz</description>
      <pubDate>Tue, 26 May 2020 19:43:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194604#M1981131</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-05-26T19:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194605#M1981132</link>
      <description>&lt;P&gt;Please indicate the error text in English. It's an English forum. It corresponds to:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Object required 424&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 May 2020 20:17:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194605#M1981132</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-05-26T20:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194606#M1981133</link>
      <description>&lt;P&gt;Hello again! &lt;/P&gt;&lt;P&gt;I edited my post again, and I'm in a new stage of VBA. &lt;/P&gt;&lt;P&gt;At this point the problem is in stopping the script in window SAP, when running VBA I can generate the file I want, but the SAP window that performed this task continues to execute it infinitely. &lt;/P&gt;&lt;P&gt;Any material or tip so that I can solve this?&lt;/P&gt;&lt;P&gt;Thanks for listening!&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Sub Cria_nova_contagem()


Set session = GetObject("SAPGUI").GetScriptingEngine.Children(0).Children(0)


Rem  B1 INICIO***********************************************


Dim objExcel
Dim objSheet, intRow, i


Set objExcel = GetObject(, "Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet




For i = 2 To objSheet.UsedRange.Rows.Count
    If i = 0 Then
    End If
    
INICIO = Trim(CStr(objSheet.Cells(7, 6).Value)) 'DATA INICIO
FIM = Trim(CStr(objSheet.Cells(7, 9).Value)) 'DATA FIM


session.findById("wnd[0]").maximize


Rem B1 FIM *************************************************


session.findById("wnd[0]/tbar[0]/okcd").Text = "/NMB51"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/txtENAME-LOW").Text = "W890230"
session.findById("wnd[1]/usr/txtENAME-LOW").SetFocus
session.findById("wnd[1]/usr/txtENAME-LOW").caretPosition = 7
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellColumn = "TEXT"
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell
session.findById("wnd[0]/usr/ctxtBUDAT-LOW").Text = INICIO
session.findById("wnd[0]/usr/ctxtBUDAT-HIGH").Text = FIM
session.findById("wnd[0]/usr/ctxtBUDAT-HIGH").SetFocus
session.findById("wnd[0]/usr/ctxtBUDAT-HIGH").caretPosition = 10
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[48]").press
session.findById("wnd[0]/mbar/menu[3]/menu[2]/menu[1]").Select
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").setCurrentCell 27, "TEXT"
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").firstVisibleRow = 18
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").selectedRows = "27"
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").clickCurrentCell
session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").Select
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "\\msbrtole004\data\Logistica\ESTOQUE\SAP"
session.findById("wnd[1]/usr/ctxtDY_PATH").SetFocus
session.findById("wnd[1]/usr/ctxtDY_PATH").caretPosition = 40
session.findById("wnd[1]/tbar[0]/btn[11]").press




Rem B2 ************************************************


Next i(0)


End Sub




Rem ****************************************************
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 May 2020 02:45:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194606#M1981133</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-05-27T02:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194607#M1981134</link>
      <description>&lt;P&gt;Hello &lt;/P&gt;&lt;P&gt;I have not programmed in Visual Basic for years... &lt;/P&gt;&lt;P&gt;If the FOR loop goes forever then I'd check the objSheet.UsedRange.Rows.Count value. Maybe it's a very large number? Otherwise put a breakpoint in the code and see what is going on.&lt;/P&gt;&lt;P&gt;It will never be zero, so this condition will never be met.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;For i = 2 To objSheet.UsedRange.Rows.Count
    If i = 0 Then
    End If&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You've got a row constant here. Should it be an I variable instead?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;INICIO = Trim(CStr(objSheet.Cells(7, 6).Value)) 'DATA INICIO
FIM = Trim(CStr(objSheet.Cells(7, 9).Value)) 'DATA FIM&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Do you want to maximize the SAP GUI for every loop pass? Isn't it enough to maximize it before the loop?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;session.findById("wnd[0]").maximize&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Do you want to open the transaction for every Excel row with data? Isn't it enough to open it before the FOR loop?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;session.findById("wnd[0]/tbar[0]/okcd").Text = "/NMB51"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[17]").press&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is zero in brackets required?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Next i(0)&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Kind regards,&lt;/P&gt;Mateusz</description>
      <pubDate>Wed, 27 May 2020 06:43:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194607#M1981134</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-05-27T06:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194608#M1981135</link>
      <description>&lt;P&gt;Thank you very much Mateusz !! &lt;/P&gt;&lt;P&gt;Your comment was very enlightening, I understood what was causing my complication, and I managed to reach my goal, in the end the code was like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Sub Cria_nova_contagem()


Set session = GetObject("SAPGUI").GetScriptingEngine.Children(0).Children(0)
session.findById("wnd[0]/tbar[0]/okcd").Text = "/NMB51"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/txtENAME-LOW").Text = "W890230"
session.findById("wnd[1]/usr/txtENAME-LOW").SetFocus
session.findById("wnd[1]/usr/txtENAME-LOW").caretPosition = 7
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellColumn = "TEXT"
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell




Rem  B1 INICIO***********************************************


Dim objExcel
Dim objSheet, intRow, i


Set objExcel = GetObject(, "Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet




For i = 2 To objSheet.UsedRange.Rows.Count
    If i &amp;lt;&amp;gt; 2 Then
    End If
    
INICIO = Trim(CStr(objSheet.Cells(7, 6).Value)) 'DATA INICIO
FIM = Trim(CStr(objSheet.Cells(7, 9).Value)) 'DATA FIM


session.findById("wnd[0]").maximize


Rem B1 FIM *************************************************






session.findById("wnd[0]/usr/ctxtBUDAT-LOW").Text = INICIO
session.findById("wnd[0]/usr/ctxtBUDAT-HIGH").Text = FIM


Rem B2 ************************************************


Next i


Rem ****************************************************


session.findById("wnd[0]/usr/ctxtBUDAT-HIGH").SetFocus
session.findById("wnd[0]/usr/ctxtBUDAT-HIGH").caretPosition = 10
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[48]").press
session.findById("wnd[0]/mbar/menu[3]/menu[2]/menu[1]").Select
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").setCurrentCell 27, "TEXT"
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").firstVisibleRow = 18
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").selectedRows = "27"
session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").clickCurrentCell
session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").Select
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "\\msbrtole004\data\Logistica\ESTOQUE\SAP"
session.findById("wnd[1]/usr/ctxtDY_PATH").SetFocus
session.findById("wnd[1]/usr/ctxtDY_PATH").caretPosition = 40
session.findById("wnd[1]/tbar[0]/btn[11]").press










End Sub


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Obrigado!!&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:06:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194608#M1981135</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-05-27T19:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Script MB51</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194609#M1981136</link>
      <description>&lt;P&gt;You're welcome! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;Mateusz</description>
      <pubDate>Wed, 27 May 2020 19:38:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-mb51/m-p/12194609#M1981136</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-05-27T19:38:55Z</dc:date>
    </item>
  </channel>
</rss>

