变量 I = i + 1 弄乱了一部分代码 (Rowcount - 4) 如何忽略这部分的变量?
variable I = i + 1 makes a mess with a part of the code (Rowcount - 4) How to ignore a variable for this part?
我的变量弄乱了我的代码部分 (Rowcount - 4, NETPR)
。我可以忽略这部分的这个变量吗?如何忽略?
'here is code to connect SAP
Dim ses As Object
i= 2
Do
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtP_VKORG-LOW").Text = "SOME"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "ZGBSTD"
Dim myGrid As Object ' here I need ignore variable
Set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell") ' here I need ignore variable
With myGrid ' here I need ignore variable
.firstVisibleRow = .RowCount - 4 ' here I need ignore variable
Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(.RowCount - 4, "NETWR") ' Here have to stay variable for Cells(i, 2)
' but variable can't chnge RowCount- 4
End With
session.findById("wnd[0]/tbar[0]/btn[3]").press
i = i + 1
Loop
'here is rest of code to end connection with SAP
更新
这是我的想法 [![最后几行][1]][1]
这是我的代码:
J=1
Do 'LAYOUT
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&FILTER"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/ctxt%%DYN001-LOW").Text = "SOME"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/btn%_%%DYN001_%_APP_%-VALU_PUSH").press
session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").Text ="SOME"
session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").caretPosition = 12
session.findById("wnd[2]/tbar[0]/btn[8]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
Set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
myGrid.currentCellColumn = "NETWR"
myGrid.selectColumn "NETWR" 'Just filtering data (COLUMN NETWR)
LastRow = myGrid.RowCount - 1
Do
'Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - 3, "NETWR")
If myGrid.getcellvalue(LastRow - j, "NETWR") <> " " Then
Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - j, "NETWR")
Exit Do
End If
j = j + 1
Loop
我想将最后一行的值粘贴到 excel
我不知道该程序总体上应该做什么,但首先我会清理一下,然后看看接下来会发生什么。
例如:
'here is code to connect SAP
Dim ses As Object
Dim myGrid As Object
i= 2
Do
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtP_VKORG-LOW").Text = "SOME"
Set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
myGrid.currentCellColumn = "ZGBSTD"
myGrid.selectColumn "ZGBSTD"
LastRow = myGrid.RowCount - 1
'every single value of the table
Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(i - 2, "NETWR")
'or always the last value
'Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - 3, "NETWR")
session.findById("wnd[0]/tbar[0]/btn[3]").press
i = i + 1
'without an exit, the loop runs indefinitely
if i - 2 > LastRow then exit do
Loop
'here is rest of code to end connection with SAP
问候,ScriptMan
我对更新的看法:
'**J=1**??
'**new**
i = 2
'**new**
Do 'LAYOUT
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&FILTER"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/ctxt%%DYN001-LOW").Text = "SOME"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/btn%_%%DYN001_%_APP_%-VALU_PUSH").press
session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").Text ="SOME"
session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").caretPosition = 12
session.findById("wnd[2]/tbar[0]/btn[8]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
Set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
myGrid.currentCellColumn = "NETWR"
myGrid.selectColumn "NETWR" 'Just filtering data (COLUMN NETWR)
LastRow = myGrid.RowCount - 1
'**new**
j = 1
'**new**
Do
'Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - 3, "NETWR")
'** "" = empty
If myGrid.getcellvalue(LastRow - j, "NETWR") <> "" Then
Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - j, "NETWR")
Exit Do
End If
j = j + 1
Loop
'**new**
i = i + 1
'if i - 2 > LastRow then exit do
Loop
'**new**
我的变量弄乱了我的代码部分 (Rowcount - 4, NETPR)
。我可以忽略这部分的这个变量吗?如何忽略?
'here is code to connect SAP
Dim ses As Object
i= 2
Do
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtP_VKORG-LOW").Text = "SOME"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "ZGBSTD"
Dim myGrid As Object ' here I need ignore variable
Set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell") ' here I need ignore variable
With myGrid ' here I need ignore variable
.firstVisibleRow = .RowCount - 4 ' here I need ignore variable
Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(.RowCount - 4, "NETWR") ' Here have to stay variable for Cells(i, 2)
' but variable can't chnge RowCount- 4
End With
session.findById("wnd[0]/tbar[0]/btn[3]").press
i = i + 1
Loop
'here is rest of code to end connection with SAP
更新 这是我的想法 [![最后几行][1]][1] 这是我的代码:
J=1
Do 'LAYOUT
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&FILTER"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/ctxt%%DYN001-LOW").Text = "SOME"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/btn%_%%DYN001_%_APP_%-VALU_PUSH").press
session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").Text ="SOME"
session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").caretPosition = 12
session.findById("wnd[2]/tbar[0]/btn[8]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
Set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
myGrid.currentCellColumn = "NETWR"
myGrid.selectColumn "NETWR" 'Just filtering data (COLUMN NETWR)
LastRow = myGrid.RowCount - 1
Do
'Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - 3, "NETWR")
If myGrid.getcellvalue(LastRow - j, "NETWR") <> " " Then
Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - j, "NETWR")
Exit Do
End If
j = j + 1
Loop
我想将最后一行的值粘贴到 excel
我不知道该程序总体上应该做什么,但首先我会清理一下,然后看看接下来会发生什么。
例如:
'here is code to connect SAP
Dim ses As Object
Dim myGrid As Object
i= 2
Do
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtP_VKORG-LOW").Text = "SOME"
Set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
myGrid.currentCellColumn = "ZGBSTD"
myGrid.selectColumn "ZGBSTD"
LastRow = myGrid.RowCount - 1
'every single value of the table
Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(i - 2, "NETWR")
'or always the last value
'Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - 3, "NETWR")
session.findById("wnd[0]/tbar[0]/btn[3]").press
i = i + 1
'without an exit, the loop runs indefinitely
if i - 2 > LastRow then exit do
Loop
'here is rest of code to end connection with SAP
问候,ScriptMan
我对更新的看法:
'**J=1**??
'**new**
i = 2
'**new**
Do 'LAYOUT
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "ZGBSTD"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&FILTER"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/ctxt%%DYN001-LOW").Text = "SOME"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/btn%_%%DYN001_%_APP_%-VALU_PUSH").press
session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").Text ="SOME"
session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").caretPosition = 12
session.findById("wnd[2]/tbar[0]/btn[8]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
Set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
myGrid.currentCellColumn = "NETWR"
myGrid.selectColumn "NETWR" 'Just filtering data (COLUMN NETWR)
LastRow = myGrid.RowCount - 1
'**new**
j = 1
'**new**
Do
'Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - 3, "NETWR")
'** "" = empty
If myGrid.getcellvalue(LastRow - j, "NETWR") <> "" Then
Sheets("AB").Cells(i, 2).Value = myGrid.getcellvalue(LastRow - j, "NETWR")
Exit Do
End If
j = j + 1
Loop
'**new**
i = i + 1
'if i - 2 > LastRow then exit do
Loop
'**new**