Macro error interfacing with SAP after Window 7 Update

dzdt56

New Member
Joined
Jul 26, 2013
Messages
4
I've created a macro that opens SAP, and downloads a number of different reports. It was working fine last week, but after an update to Windows 7 from xp (and excel 2007 to 2010), I now receive the following error during a loop in my code:

Run-time error '619'
The control could not be found by id

I have no idea what change could have caused this. If anyone has any ideas I would really appreciate it!
The error occurs at the following line:
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell[1]").setDocument 1, ""

The loop is here:
For i = StartPeriod To 13
session.findById("wnd[0]/usr/txt[7]").text = "201" & Ye
session.findById("wnd[0]/usr/txt[9]").text = "201" & Ye
session.findById("wnd[0]/usr/txt[11]").text = i
session.findById("wnd[0]/usr/txt[13]").text = i
session.findById("wnd[0]/usr/ctxt[0]").caretPosition = 9
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[45]").press
session.findById("wnd[1]/usr/sub/2/sub/2/1/rad[1,0]").select
session.findById("wnd[1]/usr/sub/2/sub/2/1/rad[1,0]").setFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxt[0]").text = OutputFilePath
session.findById("wnd[1]/usr/ctxt[1]").text = "Y1" & Ye & "P" & i & ".txt"
SendKeys "~", True
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell[1]").setDocument 1, ""
session.findById("wnd[0]/tbar[0]/btn[3]").press
If Ye <> CurrentYe And i = 13 Then
i = 0
Ye = Ye + 1
End If
If Ye = CurrentYe And i = PeriodUsed Then GoTo Line91
Next i
 
Does anyone know if this is an SAP issue or an Excel issue? I have no idea where this error is coming from.
 
Upvote 0
I'm beginning to lose hope with this problem. I have also been tackling this problem from an SAP side, but no results there either.
 
Upvote 0
I solved the problem. There seemed to be three issues with this code.

1. TheSendKeys "~", True function was not the right way of generating the report.
2. The change to Windows 7 seemed to have affected the encoding to the excel report. Defining which Encoder to use solved this.
3. This loop causes errors. I have now defined a specific number of times to loop instead of letting it break out at the correct time. Much better practice.

Below is the code. I have commented on the new additions.

For Repp = 1 To Noper
On Error Resume Next​
Kill OutputFilePath & "Y1" & Ye & "P" & i & ".txt" 'deletes the file if it already exists
On Error GoTo 0​
session.findById("wnd[0]/usr/txt[7]").text = "201" & Ye​
session.findById("wnd[0]/usr/txt[9]").text = "201" & Ye​
session.findById("wnd[0]/usr/txt[11]").text = i​
session.findById("wnd[0]/usr/txt[13]").text = i​
session.findById("wnd[0]/usr/ctxt[0]").caretPosition = 9​
session.findById("wnd[0]/tbar[1]/btn[8]").press​
session.findById("wnd[0]/tbar[1]/btn[45]").press​
session.findById("wnd[1]/usr/sub/2/sub/2/1/rad[1,0]").select​
session.findById("wnd[1]/usr/sub/2/sub/2/1/rad[1,0]").setFocus​
session.findById("wnd[1]/tbar[0]/btn[0]").press​
session.findById("wnd[1]/usr/ctxt[0]").text = OutputFilePath​
session.findById("wnd[1]/usr/ctxt[1]").text = "Y1" & Ye & "P" & i & ".txt"​
session.findById("wnd[1]/usr/ctxt[2]").text = "1160" 'Sets Encoder
session.findById("wnd[1]/usr/ctxt[2]").setFocus 'Replaces the SendKeys Method
session.findById("wnd[1]/usr/ctxt[2]").caretPosition = 4 'Replaces the SendKeys Method
session.findById("wnd[1]/tbar[0]/btn[0]").press 'Replaces the SendKeys Method
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell[1]").setDocument 1, ""​
session.findById("wnd[0]/tbar[0]/btn[3]").press​
If Ye <> CurrentYe And i = 13 Then​
i = 0​
Ye = Ye + 1​
End If​
i = i + 1​
Next Repp
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top