1

I use VBA to show 1 value from SAP (Total in COOIS). All works well but I have to type the value into Excel because the Total value is every time on another position, and I can't find how to copy into Excel. All is automated: Filters working fine, resize works fine, Set total for row works fine.

enter image description here

Code:

'COOIS Get Total
    
Option Explicit
Public SapGuiAuto, WScript, msgcol
Public objGui  As GuiApplication
Public objConn As GuiConnection
Public session As GuiSession
    
Sub SAPDownloadAttachment()
    
    Set SapGuiAuto = GetObject("SAPGUI")
    Set objGui = SapGuiAuto.GetScriptingEngine
    Set objConn = objGui.Children(0)
    Set session = objConn.Children(0)
  
     'About this I'm not sure:
 
      'Define Variables
      '    Dim WB As Workbook
      '    Dim WS As Worksheet
      '   Dim LR As Long
      '   Dim i As Long                                               
                                                                
    '  Set WB = ThisWorkbook
    '    Set WS = WB.Worksheets("TEST")
                                                                
    '   LR = WS.Cells(Rows.count, 1).End(xlUp).Row
                                                                
    
    session.findById("wnd[0]").resizeWorkingPane 126, 43, False
    session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00023"
    session.findById("wnd[0]/usr/ssub%_SUBSCREEN_TOPBLOCK:PPIO_ENTRY:1100/ctxtPPIO_ENTRY_SC1100-ALV_VARIANT").SetFocus
    session.findById("wnd[0]/usr/ssub%_SUBSCREEN_TOPBLOCK:PPIO_ENTRY:1100/ctxtPPIO_ENTRY_SC1100-ALV_VARIANT").caretPosition = 11
    session.findById("wnd[0]").sendVKey 4
    session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").currentCellColumn = "TEXT"
    session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").doubleClickCurrentCell
    session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_WERKS-LOW").Text = "p120"
    session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_ARBPL-LOW").Text = "132"
    session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_ISTEN-LOW").SetFocus
    session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_ISTEN-LOW").caretPosition = 0
    session.findById("wnd[0]").sendVKey 4
    session.findById("wnd[1]/usr/cmbWORKFLDS-MONTH").SetFocus
    session.findById("wnd[1]/usr/cmbWORKFLDS-MONTH").Key = "1"
    session.findById("wnd[1]/usr/cmbWORKFLDS-YEARN").SetFocus
    session.findById("wnd[1]/usr/cmbWORKFLDS-YEARN").Key = "2025"
    session.findById("wnd[1]/usr/sub:SAPLSHLC:0200[0]/txtIOWORKFLDS-DAY03[0,6]").SetFocus
    session.findById("wnd[1]/usr/sub:SAPLSHLC:0200[0]/txtIOWORKFLDS-DAY03[0,6]").caretPosition = 1
    session.findById("wnd[1]").sendVKey 2
    session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_ISTEN-HIGH").SetFocus
    session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_ISTEN-HIGH").caretPosition = 0
    session.findById("wnd[0]").sendVKey 4
    session.findById("wnd[1]/usr/cmbWORKFLDS-MONTH").SetFocus
    session.findById("wnd[1]/usr/cmbWORKFLDS-MONTH").Key = "1"
    session.findById("wnd[1]/usr/cmbWORKFLDS-YEARN").SetFocus
    session.findById("wnd[1]/usr/cmbWORKFLDS-YEARN").Key = "2050"
    session.findById("wnd[1]/usr/sub:SAPLSHLC:0200[0]/txtIOWORKFLDS-DAY06[0,15]").SetFocus
    session.findById("wnd[1]/usr/sub:SAPLSHLC:0200[0]/txtIOWORKFLDS-DAY06[0,15]").caretPosition = 1
    session.findById("wnd[1]").sendVKey 2
    session.findById("wnd[0]/tbar[1]/btn[8]").press
    session.findById("wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell").currentCellRow = -1
    session.findById("wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell").selectColumn "GWEMG"
    session.findById("wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell").pressToolbarButton "&NAVIGATION_PROFILE_TOOLBAR_EXPAND"
    session.findById("wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell").pressToolbarContextButton "&MB_SUM"
    session.findById("wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell").selectContextMenuItem "&SUMC"
    
    
    MsgBox "Close this message and put Total in Excel"
    
    'Set back to Main Page
    session.findById("wnd[0]").resizeWorkingPane 126, 43, False
    session.findById("wnd[0]/tbar[0]/btn[15]").press
    session.findById("wnd[0]").resizeWorkingPane 126, 43, False
    session.findById("wnd[0]/tbar[0]/btn[15]").press
    
    'Stop Macro
    Application.VBE.CommandBars.FindControl(ID:=228).Execute
    
End Sub
4
  • 1
    "Bot-editor tells me ..." If this post is just a re-post of a previously deleted post, the result probably isn't going to be different. Commented Jun 25 at 8:35
  • 1
    "Bot-editor tells me ..." means that the question is maybe not precise enough, which is the case here: why posting code which is not related to the question? A precise question would be how to know the number of lines of a GuiGridView Object, how to scroll to a given line number, how to read a value from this line... (which are 3 different questions so 3 different posts.) All these different questions are answered in Stack Overflow (e.g. stackoverflow.com/a/65577250/9150270). I removed "Bot-editor tells me..." Commented Jun 26 at 17:09
  • If you want to have the total line always on the top you could change the layout in SAP. There is an option to Display total lines above the entries Commented Jun 27 at 7:43
  • I apologize for the previous miserable expression. Thank you all who put time in this. I've seen an edit of my problem description in this post but it disappeared, this was really a good sample. Today I solved the issue with chatgpt. The good thing is that there is no patience needed on both sides. I can ask the most noob questions until I understand. Even with my few knowledge it was working out. Commented Jun 27 at 10:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.