Extract content from DataGridView from SAP to Excel with Macro

0

I'm having trouble passing the contents of a DataGridView SAP to Excel with a macro.

I get the error:

  

"The object does not support this property"

Here where you mark me in the VBA

This is the code section:

Sub creadorGD()

Dim application
Dim connection
Dim GridView As Object

Set objsheet = ActiveWorkbook.ActiveSheet

H = Range("B7")
sucursal = Range("C7")
'    .......  



'priemra parte
'session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nZ_GD_MAQUINA"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtKNA1-KUNNR").Text = centro
session.findById("wnd[0]/usr/ctxtW_FECHA").Text = fecha
session.findById("wnd[0]/usr/ctxtTVSTZ-WERKS").Text = "1003"
session.findById("wnd[0]/usr/ctxtZAREAVTA-BUKRS").Text = "1000"
session.findById("wnd[0]/usr/txtW_TEXTO").Text = receptor
session.findById("wnd[0]/usr/txtW_TEXTO").SetFocus
'session.findById("wnd[0]/usr/txtW_TEXTO").caretPosition = 18
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/txtW_TEXTO").Text = receptor
session.findById("wnd[0]/usr/txtW_TEXTO").SetFocus
'session.findById("wnd[0]/usr/txtW_TEXTO").caretPosition = 18
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/btnBTN_MATCH").press
session.findById("wnd[1]/usr/lbl[21,5]").SetFocus
'session.findById("wnd[1]/usr/lbl[21,5]").caretPosition = 64
session.findById("wnd[1]").sendVKey 2
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-ARKTX[0,0]").Text = H
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-KWMENG[1,0]").Text = "1"
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-NETWR[2,0]").Text = "1"
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-NETWR[2,0]").SetFocus
session.findById("wnd[0]/usr/tblZSD_GENERA_ZSGCDETALLE/txtT_DETALLE-NETWR[2,0]").caretPosition = 7
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/btnGENERAR").press
'favor copiar numero
'MsgBox "favor guarde numero de guia, muy importante"
'myText = session.findById("wnd[1]/usr/cntlCC1/shellcont/shell").Text
'myText = rigth(myText, 8)

myText = session.findById("wnd[1]/usr/cntlCC1/shellcont/shell").Text
myText = Right(myText, 9)
 ' Selection.Copy


'segunda parte

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nIDCP"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/radCHK_DELI").Select
session.findById("wnd[0]/usr/ctxtL_VSTEL").Text = "1003"
session.findById("wnd[0]/usr/ctxtWERKS").Text = "1003"
session.findById("wnd[0]/usr/ctxtWERKS").SetFocus
session.findById("wnd[0]/usr/ctxtWERKS").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtLOTNO").Text = "gd48"
session.findById("wnd[0]/usr/ctxtBOKNO").Text = "07"
session.findById("wnd[0]/usr/radCHK_PRI").SetFocus
session.findById("wnd[0]/tbar[1]/btn[8]").press
'pegar numero

session.findById("wnd[1]/usr/chkWBSTK_AB").Selected = True
session.findById("wnd[1]/usr/txtL_ERNAM-LOW").Text = "fmoraless"
session.findById("wnd[1]/usr/ctxtL_VBELN-LOW").Text = myText
session.findById("wnd[1]/usr/ctxtLMSGTYPE").Text = "zmg0"


session.findById("wnd[1]/usr/ctxtL_VBELN-LOW").SetFocus
session.findById("wnd[1]/usr/ctxtL_VBELN-LOW").caretPosition = 8
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellColumn = ""
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectedRows = "0"
session.findById("wnd[0]/tbar[1]/btn[46]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellColumn = "XBLNR"


'ingresar numero guardado
'MsgBox "PEGE el numero donde se pide"
'session.findById("wnd[1]/usr/ctxtLMSGTYPE").Text = "zmg0"
'MsgBox "copie el numero donde se pide"
'session.findById("wnd[1]/usr/chkWBSTK_AB").SetFocus
'session.findById("wnd[1]/tbar[0]/btn[8]").press
'session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellColumn = myText.Value
'session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectedRows = "0"
'session.findById("wnd[0]/tbar[1]/btn[46]").press
'session.findById("wnd[1]/tbar[0]/btn[0]").press

'numerro ge guia
Set GridView = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[0]/shell")
'session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[0]/shell").setCurrentCell 1, "ZSGC"

For i = 0 To GridView.ColumnCount - 1
    Cells(13, i + 1).Value = GridView.GetColumnTitles(GridView.ColumnOrder(i))(0)
Next i

For i = 0 To GridView.ColumnCount - 1
    For j = 0 To GridView.RowCount - 1
        Cells(14 + j, i + 1).Value = GridView.GetCellValue(j, GridView.ColumnOrder(i))
    Next j
Next i





MsgBox "script completado", vbOKOnly, vbInformation

'session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellColumn = ""
'session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectedRows = "0"


End Sub
    
asked by Francisco Morales 09.09.2018 в 06:15
source

1 answer

0

If the following is true:

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellColumn = "XBLNR"

Then this should read as follows:

Set GridView = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")

Greetings, ScriptMan

    
answered by 12.09.2018 / 13:00
source