on 06-21-2016 2:22 PM
I have created a VBA script to copy sales texts from orders through VA03
The script is copying the texts, but is not keeping the line break that exists in SAP. Is there something I can do to keep the line breaks when text is copied to excel?
Below you have the piece of the code that is copying from SAP and storing the text in a variable
objSess.FindById("wnd[0]").Maximize
objSess.FindById("wnd[0]/usr/ctxtVBAK-VBELN").Text = ""
objSess.FindById("wnd[0]/tbar[0]/okcd").Text = "/nva03"
objSess.FindById("wnd[0]").sendVKey 0
objSess.FindById("wnd[0]/usr/ctxtVBAK-VBELN").Text = W_OrderNumber
objSess.FindById("wnd[0]/usr/ctxtVBAK-VBELN").caretPosition = 9
objSess.FindById("wnd[0]").sendVKey 0
objSess.FindById("wnd[0]/mbar/menu[2]/menu[1]/menu[10]").Select
objSess.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell").SelectItem W_Text, "Column1"
objSess.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell").EnsureVisibleHorizontalItem W_Text, "Column1"
objSess.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\09/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell").DoubleClickItem W_Text, "Column1"
objSheet.Cells(iRow, 6).WrapText = True
objSheet.Cells(iRow, 6) = objSess.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").Text
objSess.FindById("wnd[0]/tbar[0]/btn[3]").press
objSess.FindById("wnd[0]/tbar[0]/btn[3]").press
Thanks,
Francine
Hello Francine,
welcome in the Scripting Language forum.
You can try this - I marked the important code red:
Public SapGuiAuto As Object
Public app As GuiApplication
Public conn As GuiConnection
Public sess As GuiSession
Public txtedit As GuiTextedit
Sub Test()
Dim Lines As Long
Dim LineText As String
Dim Text As String
Set SapGuiAuto = GetObject("SAPGUI")
Set app = SapGuiAuto.GetScriptingEngine
Set conn = app.Children(0)
Set sess = conn.Children(0)
'Here I get the TextEdit control
Set txtedit = sess.FindById("wnd[0]/shellcont/shell")
'In your case
'Set txtedit = _
'objSess.FindById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell")
Lines = txtedit.LineCount
'Here I read line by line from the TextEdit control and set between
'each line a break
Text = ""
For i = 1 To Lines
LineText = txtedit.GetLineText(i) + Chr(10)
Text = Text & LineText
Next
ActiveCell.Value = Text
End Sub
So I get this result:
I check it also with VBScript, and here it works a little bit easier:
Let us know your results.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan! Hope you receive this notification!
I'm facing the same issue with getting text from a shell container with the line breaks.
I've been trying to test your solution, but I believe I'm missing the vba reference that allows me to use 'txtedit As GuiTextedit'
Would you mind pointing me in the right direction?
Hi there,
You have a question and need help by the community? Instead of posting into an old question thread, it is more helpful for you, if you create your own question. Here is how to get started:
That's it. Thank you!
Best regards,
Your SAP Community moderator
Hello.
We had this requirement few times in nearly past. Always the best Solution for this was using RFC call of functionmodule RFC_READ_TEXt called in Excel VBA Macro. You will find a few solutions how To so in this Forum.
REgards
HOlger
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.