Sap Script

MIGO – Capturando informações com Excel VBA

Nessa postagem vou demonstrar como fazer a leitura e captura de dados do SAP através da TCode MIGO, utilizando a funcionalidade Sap Gui Scripting em conjunto com Excel VBA.

Vou utilizar como exemplo o modelo abaixo:

Abaixo a tela da MIGO referenciando os itens marcados acima com os campos no SAP.

Vou utilizar o arquivo padrão que utilizo para todas as minhas automações, disponível na postagem https://fabiomitsueda.com.br/sap-script-vba-conexao/ E abaixo o código comentado que vou utilizar nesse exemplo:

'Autor: Fabio Mitsueda
'Contato: mitsueda.fabio@gmail.com
'Data Criação: 20/05/2023
Option Explicit
Option Private Module

Public Sub Executar1()
Dim shtBase         As Worksheet
Dim h, i, z   As Long
Dim intRowVisible   As Integer
Dim fCheck          As Boolean
Dim Table           As Object

'Carregando variavel de objeto
Set shtBase = ThisWorkbook.Sheets(ActiveSheet.Name)

'Limpar dados pre-preenchido
shtBase.Range("A6:F1005").ClearContents

'Acessando a MIGO
Session.findById("wnd[0]/tbar[0]/okcd").Text = "MIGO"

'Enviando a tecla enter
Session.findById("wnd[0]").sendVKey 0

'Opção exibir
Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_FIRSTLINE:SAPLMIGO:0010/cmbGODYNPRO-ACTION").Key = "A04"

'Inserir numero da MIGO
Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_FIRSTLINE:SAPLMIGO:0010/subSUB_FIRSTLINE_REFDOC:SAPLMIGO:2010/txtGODYNPRO-MAT_DOC").Text = shtBase.Cells(1, 2).Value

'Inserindo ano da MIGO
Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_FIRSTLINE:SAPLMIGO:0010/subSUB_FIRSTLINE_REFDOC:SAPLMIGO:2010/txtGODYNPRO-DOC_YEAR").Text = shtBase.Cells(1, 3).Value

'Enviando enter
Session.findById("wnd[0]").sendVKey 0

'Carregado variavel da tabela de itens
Set Table = Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMLIST:SAPLMIGO:0200/tblSAPLMIGOTV_GOITEM")

'Capturando a quantidade de registros na tabela
z = Table.RowCount - 1

'Capturando a quantidade de linhas visiveis por tela
intRowVisible = Table.VisibleRowCount

'Iniciando contador de itens por tela
h = 0

'Loop de repetição para itens da tabela de itens
For i = 0 To z
    
    'Selecionando a guia Material
    Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMDETAIL:SAPLMIGO:0301/subSUB_DETAIL:SAPLMIGO:0300/tabsTS_GOITEM/tabpOK_GOITEM_MATERIAL").Select
    
    'Movendo a barra de rolagem e atualizando a posição da linha
    If i Mod intRowVisible = 0 Then
        Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMLIST:SAPLMIGO:0200/tblSAPLMIGOTV_GOITEM").verticalScrollbar.Position = i
        h = 0
        DoEvents
    End If
    
    'Sair do lanço de repetição caso não exista mais itens na tabela
    If Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMLIST:SAPLMIGO:0200/tblSAPLMIGOTV_GOITEM/btnGOITEM-ZEILE[0," & h & "]").Text = "____" Then
        Exit For
    End If
    
    'Selecionando a linha
    Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMLIST:SAPLMIGO:0200/tblSAPLMIGOTV_GOITEM/btnGOITEM-ZEILE[0," & h & "]").SetFocus
    Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMLIST:SAPLMIGO:0200/tblSAPLMIGOTV_GOITEM/btnGOITEM-ZEILE[0," & h & "]").press
    shtBase.Cells(6 + i, 1).Value = Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMLIST:SAPLMIGO:0200/tblSAPLMIGOTV_GOITEM/btnGOITEM-ZEILE[0," & h & "]").Text
            
    'Material
    shtBase.Cells(6 + i, 2).Value = Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMDETAIL:SAPLMIGO:0301/subSUB_DETAIL:SAPLMIGO:0300/tabsTS_GOITEM/tabpOK_GOITEM_MATERIAL/ssubSUB_TS_GOITEM_MATERIAL:SAPLMIGO:0310/ctxtGOITEM-MATNR").Text
            
    'Selecioando a guia de quantidade
    Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMDETAIL:SAPLMIGO:0301/subSUB_DETAIL:SAPLMIGO:0300/tabsTS_GOITEM/tabpOK_GOITEM_QUANTITIES").Select
    
    'Quantidade
    shtBase.Cells(6 + i, 3).Value = VBA.CDbl(Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMDETAIL:SAPLMIGO:0301/subSUB_DETAIL:SAPLMIGO:0300/tabsTS_GOITEM/tabpOK_GOITEM_QUANTITIES/ssubSUB_TS_GOITEM_QUANTITIES:SAPLMIGO:0315/txtGOITEM-ERFMG").Text)
    
    'Unidade medida
    shtBase.Cells(6 + i, 4).Value = Session.findById("wnd[0]/usr/ssubSUB_MAIN_CARRIER:SAPLMIGO:0003/subSUB_ITEMDETAIL:SAPLMIGO:0301/subSUB_DETAIL:SAPLMIGO:0300/tabsTS_GOITEM/tabpOK_GOITEM_QUANTITIES/ssubSUB_TS_GOITEM_QUANTITIES:SAPLMIGO:0315/ctxtGOITEM-ERFME").Text
        
    'Atualizando a linha de referencia
    h = h + 1

Next

'Enviando a tecla enter
Session.findById("wnd[0]").sendVKey 0
        
MsgBox "Finalizado!!!"

'Descarregando Variavel de objeto
Set shtBase = Nothing
Set Table = Nothing
End Sub

 

Clique aqui para baixar o arquivo exemplo dessa postagem.

5 comentários sobre “MIGO – Capturando informações com Excel VBA”

  • Great experience so far. The game variety is impressive and I had a lucky streak yesterday. Highly recommend idgbo303 to anyone looking for some action.

    Resposta
  • Great customer support and a very professional layout. It is hard to find a site this reliable these days. I will definitely be sticking with idroyal1000.

    Resposta
  • The VIP program here is truly one of the best I have come across in the online gaming scene. I love how they reward loyal players with genuine perks instead of just empty promises. Customer support is always ready to help and the withdrawals are surprisingly fast. Keep up the amazing work team. 23winvip

    Resposta
  • I switched from my old site last month and the difference is night and day. Customer service responds in minutes and the withdrawal limits are actually reasonable for local players. I enjoy the weekly promotions and the game selection feels fair. Keep up the great work team 77bdbet

    Resposta

Deixe uma resposta