on 04-21-2016 6:08 PM
Hi All,
I am trying to extract sale text from MM03 for a few items.
I am able to extract it; but the problem is that if the sales text is in different lines that is it has more than 1 line one below the other as content, I am getting everything in one line in excel and not as in SAP.
Can someone help
Sub salestext()
Dim t As String
Set SapGuiAuto = GetObject("SAPGUI")
Set App = SapGuiAuto.GetScriptingEngine
Set Connection = App.Children(0)
Set session = Connection.Children(0)
For i = 2 To Sheets("Data").Range("A1048576").End(xlUp).Row
session.findById("wnd[0]").maximize session.findById("wnd[0]/tbar[0]/okcd").Text = "mm03"
session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").Text = Sheets("Data").Range("A" & i)
session.findById("wnd[0]").sendVKey 0 session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").Text = "3601"
session.findById("wnd[1]/tbar[0]/btn[0]").press On Error GoTo skip session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP08").Select
session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").Text = "3601"
session.findById("wnd[1]/usr/ctxtRMMG1-VTWEG").Text = "00"
session.findById("wnd[1]/usr/ctxtRMMG1-VTWEG").SetFocus
session.findById("wnd[1]/usr/ctxtRMMG1-VTWEG").caretPosition = 2
session.findById("wnd[1]/tbar[0]/btn[0]").press
t = session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP08/ssubTABFRA1:SAPLMGMM:2010/subSUB2:SAPLMGD1:2121/cntlLONGTEXT_VERTRIEBS/shellcont/shell").Text
session.findById("wnd[0]/tbar[0]/btn[3]").press
Sheets("Data").Cells(i, 3) = t
skip:
session.findById("wnd[0]/tbar[0]/btn[3]").press
Next
End Sub .
Hello.
I have created an Excel macro which call RFC-enabled functionmodule RFC_READ_TEXT.
I would suggest to use same method as all other Options have not solved my requirements.
Create an Excel worksheet as in attached Picture.
Insert attached Textfile Content in Excel VBA module.
Add two Buttons on worksheet and assign macro "RFC_Read_Table" to extract button and macro "Clear_Sheet_Data" to button for clear Content on worksheet.
Hope this help to achieve your requirements.
Best regards,
Holger
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Holger Kohn,
First of all I apologize for replying very late.
I tried your code.
But I am getting No sales text exist in column D
and Return message as Text 000000000000000001C36000 ID 0001 language EN not found
for material 000001 and similarly no values for other materials as well.
Can you teach me( or get me some documents/site where I can learn RFC technique) RFC.
I am totally new to it and would like to learn it fully.
Anyways thanks a lot for the valuable code (at least I could get a small idea of RFC).
I am sure It might be just a few tweaks in the code and it will be all OK.
Regards
Krishna Kumar
Hello.
I suggest to check Longtext Header if your Setup is similar to my Systems:
In MM02 on Sales Text tab call Longtext Editor:
Then goto 'Header':
Check Text Name with Returnmessage from Excel macro-enabled template.
Below the logic from macro and screenshot of Sales Text Header -> I guess this Need no further explaination. If Text Name from Returnmessage is different to below from Text Header you Need to adjust macro logic that it will fit to your System requirements.
tblText_Lines(1, "TDOBJECT") = "MVKE"
tblText_Lines(1, "TDSPRAS") = ThisWorkbook.Sheets("Data").Cells(iRow, 3).Value
tblText_Lines(1, "TDNAME") = strMATNR & ThisWorkbook.Sheets("Data").Cells(iRow, 2).Value & "00"
tblText_Lines(1, "TDID") = "0001"
Hope this helps.
Best regards
Holger
Holger,
Do I require something like RFC Connection (I do not know the exact name) to be enabled.
I felt like asking this as I saw some youtube videos regarding RFC and it showed like enabling something in SM37 or so.
I am very new to SAP scripting and have not seen any code having something related to RFC until now.
Sorry, if I spoiled your time.
Regards
Krishna Kumar
Hello.
As you have get an returnmessage back everything is ok with RFC authorization aso.
In case of missing technical or role authorization you will get an runtime error. As this is not the case here it should be fine.
Please make a screenshot of Editor Header for Sales longtext object.
I strongly believe it has something to do with the Text Name creation in macro code.
Thanks.
Br, Holger
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.