cancel
Showing results for 
Search instead for 
Did you mean: 

Record Macro MSG

Former Member
0 Kudos

Hello all,

Good day.

I am using record macro code to create PO in excel.

Coding Working fine.

But once PO Created i want the PO no in the Excel Column B.

Please Help.


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



Set xclapp = CreateObject("Excel.Application")
Set xclapp = CreateObject("Excel.Application")
Set xclwbk = xclapp.Workbooks.Open("c:\tmp\prices.xlsx")
set xclsht = xclwbk.Sheets("Sheet1")

i = 2

While (not xclsht.Cells(i, 1).Value = "")
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nm2n"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0016/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").modifyCell 0,"BNFPO",xclsht.cells(i,1).Value
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press


  i = i + 1
Wend




msgbox "All " & cstr(xclapp.ActiveCell.SpecialCells(11).Row - 1) & " Excel rows have been processed."
 
Set xclwbk = Nothing
Set xclsht = Nothing
xclapp.Quit
set xclapp = Nothing

Edited by: hpvinu on Mar 1, 2012 5:14 PM

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Once PO Saved

in the bottom " MSG will Come " Like PO XXXXX Created.

I want the MSG in my Excel B Column.

Former Member
0 Kudos

After reading your script, I noticed that you have not called the column B, you are just using A2 downward.

Anyway, once I am done installing my SAP ABAP, I might help you on that. Btw, I am new here _.

Regards,

Bishbi

Former Member
0 Kudos

Any Reply really appreciated....

michael_hobbins
Active Participant
0 Kudos

On the Cells part, 2 represents column B, so

xclsht.Cells(i, 2).Value = <result>

This line must go before

i = i + 1

As I don't work with this SAP scripts I don't know which command returns your PO number which I represented as <result> in the first part.

Cheers,

Michael

thomas_brutigam2
Active Participant
0 Kudos

Hi,

late but i hope I can be of service ...

you can read the "Bottom" (which is actually The Statusbar as Following:

session.findbyid("wnd[0]/usr/sbar").MessageId -> or

session.findbyid("wnd[0]/usr/sbar").Text (the displayed Text) and then you just have to look for

PO Number in the returned String:

PO_Number = session.findbyid("wnd[0]/usr/sbar").Text

dummy() = Split("PO_Number"," ")

xclsht.cells(i,2).Value = dummy(1)

This should work in case th PO-Number is the second thing in the Statusline Text