Minx_Minxy
New Member
- Joined
- Jul 13, 2015
- Messages
- 22
- Office Version
- 365
- Platform
- Windows
Hi I have the code below that is not working. I have two problems, it runs for the first row of my file then the message box pops up and then it stops and then if I run again, it restarts from the top and it replaces the numbers on column E with new numbers.
1) How do I get the macro to re-initiate after the message box pops up and the user manually fixes the error?
2) How do I have the macro not restarting from the top and replacing the numbers that it already has pasted in column E? i.e.: Continue from where it left off
1) How do I get the macro to re-initiate after the message box pops up and the user manually fixes the error?
2) How do I have the macro not restarting from the top and replacing the numbers that it already has pasted in column E? i.e.: Continue from where it left off
VBA Code:
Sub Create()
Dim application
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
Dim lastrow As Variant
Dim i As Long
lastrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow
On Error GoTo message
session.findById("wnd[0]/tbar[0]/okcd").Text = "/niw21"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRIWO00-QMART").Text = "m7"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSCREEN_1:SAPLIQS0:1050/subNOTIF_TYPE:SAPLIQS0:1052/txtVIQMEL-QMTXT").Text = Range("a" & i).Value 'Text value
session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB01/ssubSUB_GROUP_10:SAPLIQS0:7235/subCUSTOM_SCREEN:SAPLIQS0:7212/subSUBSCREEN_1:SAPLIQS0:7322/subOBJEKT:SAPLIWO1:0100/ctxtRIWO1-TPLNR").Text = Range("b" & i).Value 'FuncLoc
session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB01/ssubSUB_GROUP_10:SAPLIQS0:7235/subCUSTOM_SCREEN:SAPLIQS0:7212/subSUBSCREEN_1:SAPLIQS0:7322/subOBJEKT:SAPLIWO1:0100/ctxtRIWO1-EQUNR").Text = Range("c" & i).Value 'Equipment
session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB01/ssubSUB_GROUP_10:SAPLIQS0:7235/subCUSTOM_SCREEN:SAPLIQS0:7212/subSUBSCREEN_4:SAPLIQS0:7715/cntlTEXT/shellcont/shell").Text = Range("d" & i).Value 'Description
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/okcd").Text = "/niw23"
session.findById("wnd[0]").sendVKey 0
Range("e" & i).Value = session.findById("wnd[0]/usr/ctxtRIWO00-QMNUM").Text 'Get Notification Number
message:
MsgBox "There is an error, please check your SAP screen, revise the error and press OK"
i = i + 1
Exit Sub
Resume Next
Next i
End Sub