Quantcast
Channel: SCN: Message List - Scripting Languages
Viewing all 1708 articles
Browse latest View live

Re: Gathering MHTML reports

$
0
0

Hello Holgar!

 

Thank you very much for your reply.

 

My purpose was to be able to gather all the ALV-grid info into one excel file.

(For many diff. order numbers, all gathered into one file)

 

When I tried the above script, the furthest it took me was to display mode...

 

Is there any way I am able to transfer this into excel file (and save)?

Capture.PNG

Thank you once again!

 

BR, Cathy

 

 

* What I have so far *

 

Sub GetPlanCostData()
'---------------------------------
  '---------------------------------
' Parameters


'---------------------------------
   '-------- SAP LOGIN --------------
   '---------------------------------


    'If Right(CLPdirName, 1) <> "\" Then CLPdirName = CLPdirName & "\"

    On Error Resume Next

    If SAPApp Is Nothing Then
        Set SapGuiApp = GetObject("SAPGUI")
        Set SAPApp = SapGuiApp.GetScriptingEngine
       ' If SAPApp Is Nothing Then GoTo Exit_AllReport
    End If
    If Connection Is Nothing Then
        Set Connection = SAPApp.Children(0)
    End If
    If Session Is Nothing Then
        Set Session = Connection.Children(0)
    End If

Set GRID = Session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")
GRID.setCurrentCell -1, ""
Row = GRID.currentCellRow
CELL = GRID.getcellvalue(Row, "COLUMN_NAME")

 

' Get data for paging-down

RowCount = GRID.RowCount

VisibleRows = GRID.VisibleRowCount

VisiblePages = (RowCount / VisibleRows) - 1

 

' Get current column selected by user

SelectedColumn = GRID.CurrentCellColumn

GRID.selectColumn SelectedColumn

GRID.FirstVisibleRow = GRID.RowCount - 1

 

'Page to bottom of ALV

For Pages = 1 To VisiblePages

    GRID.FirstVisibleRow = (Pages * VisibleRows)

Next

 

' Select all text

GRID.contextMenu

GRID.SelectContextMenuItemByPosition "0"

 

' Return to first row

GRID.FirstVisibleRow = 0

GRID.ClearSelection

GRID.currentCellRow = 0

GRID.CurrentCellColumn = SelectedColumn

 

 

'MsgBox "Number of records: " & Grid.RowCount, vbInformation, "Count of Records"

 

' Cancel popup message (Not all data has been copied into the clipboard)

On Error Resume Next

    Session.FindById("wnd[1]/tbar[0]/btn[0]").press

On Error GoTo 0

    If Err = 0 Then flgSapIsOpen = True
    Err.Clear
   
    On Error GoTo 0

    If flgSapIsOpen = False Then
        Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
        Set Connection = SapGuiApp.OpenConnection(CLPsapName, True, False)
      '  If Connection Is Nothing Then GoTo Exit_AllReport
   '?     Set session = Connection.Children(0)

        If Not IsObject(Connection) Then
            Set Connection = SAPApp.Children(0)
        End If
        If Not IsObject(Session) Then
            Set Session = Connection.Children(0)
        End If

    End If

'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

'Start Processing in SAP
i = 2

SO = Cells(i, 1)


    Session.FindById("wnd[0]").maximize
    Session.FindById("wnd[0]/tbar[0]/okcd").Text = "/niw33"
    Session.FindById("wnd[0]").sendVKey 0
    Session.FindById("wnd[0]/usr/ctxtCAUFVD-AUFNR").Text = SO
    Session.FindById("wnd[0]/tbar[1]/btn[8]").press
    Session.FindById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1107/tabsTS_1100/tabpKOAU/ssubSUB_AUFTRAG:SAPLICO1:1100/btnPUSH1").press
    ThisWorkbook.Sheets(2).Activate
    Set Table_Message = Session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")
    Set Cols = Table_Message.ColumnOrder()
    ROW_COUNT = Table_Message.RowCount() - 1
    COL_COUNT = Table_Message.ColumnCount() - 1
   
    For i = 0 To ROW_COUNT
        For j = 0 To COL_COUNT
            DoEvents
            If i = 0 Then ThisWorkbook.Sheets(2).Cells(i + 1, j + 1).Value = Table_Message.GetDisplayedColumnTitle(CStr(Cols(j)))
            ThisWorkbook.Sheets(2).Cells(i + 2, j + 1).Value = Table_Message.getcellvalue(i, CStr(Cols(j)))
        Next
    Next
   
Columns.AutoFit


SAP_Workbook = "Worksheet in Basis (1)"
EXCEL_Path = "C:\SAP\"
myWorkbook = "Report.xlsx"

End Sub


Re: Focus on SAP window using VBA

$
0
0

Good afternoon everyone
I need help
I have carefully read several reviews on the web on this subject
I have a problem to define and create the script that need
Can you help ?
I have to attach a document to multiple clients using " PCATTA_CREA "
First I want to know how to do one with a script
Then I want to automate with vba script in a loop and attach to a different document
for each client in an Excel list
I recorded the script but do not know how to include the url of the file you want
in the " import file"
I think I've read everything but I just do not create the right script
I do not speak English and my knowledge of sap and vbs are rudimentary
Can anyone complete the script to work ?
Thanks to all
I have Excel 2010 and SAP 720
Then I show the two macros I've created
The first is the one that opens the "import file" in the transaction CIC0
The second isone that includes the attached
(both thanks to the contributions of SCRIPTMAN, SAYUTI, UMUR and others. Took a
year reading your contributions and all are very good)

 

 

 

Sub intentando_anexar_documentos_en_SAP()

 

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

 

  • session.findById("wnd[0]").maximize
  • session.findById("wnd[0]/tbar[0]/okcd").Text = "/NCIC0"
  • session.findById("wnd[0]").sendVKey 0
  • session.findById("wnd[1]/usr/lbl[22,4]").SetFocus
  • session.findById("wnd[1]/usr/lbl[22,4]").caretPosition = 3
  • session.findById("wnd[1]").sendVKey 2
  • session.findById("wnd[0]/usr/sub/1/tabsCCONT_CONTROL/tabpCCONT_TAB01/ssub/1/1/2/sub/1/1/2/1/txt[1]").Text = "10591671" ‘customer number
  • session.findById("wnd[0]/usr/sub/1/tabsCCONT_CONTROL/tabpCCONT_TAB01/ssub/1/1/2/sub/1/1/2/1/txt[1]").SetFocus
  • session.findById("wnd[0]/usr/sub/1/tabsCCONT_CONTROL/tabpCCONT_TAB01/ssub/1/1/2/sub/1/1/2/1/txt[1]").caretPosition = 8
  • session.findById("wnd[0]").sendVKey 0
  • session.findById("wnd[1]/usr/lbl[1,3]").caretPosition = 2
  • session.findById("wnd[1]").sendVKey 2
  • session.findById("wnd[0]").sendVKey 0

  • session.findById("wnd[0]/usr/sub/1/tabsCCONT_CONTROL/tabpCCONT_TAB01/ssub/1/1/2/btn[2]").press
  • session.findById("wnd[0]/titl/shellcont/shell").pressButton "%GOS_TOOLBOX"
  • session.findById("wnd[0]/shellcont/shell").pressContextButton "CREATE_ATTA"

  • session.findById("wnd[0]/shellcont/shell").SelectContextMenuItem "PCATTA_CREA"

  • session.findById("wnd[0]/shellcont").Close

'session.findById("wnd[0]/tbar[0]/btn[3]").press

Set SapGuiAuto = Nothing

Set application = Nothing

Set connection = Nothing

Set session = Nothing

 

End Sub

 

 

-----------------------------------------------------------------------------

 

 

Sub script_para_anexar_archivo()

 

Set Wshell = CreateObject("WScript.Shell")

Do

bWindowFound = Wshell.AppActivate("importfile")

waitTill = Now() + TimeValue("00:00:01")

While Now() < waitTill

DoEvents

Wend

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("importfile")

If (bWindowFound) Then

  • Wshell.AppActivate "importfile"

waitTill = Now() + TimeValue("00:00:01")

While Now() < waitTill

DoEvents

Wend

  • Wshell.SendKeys "{ENTER}"

  • Wshell.SendKeys Excel.Sheets(1).Cells(31, 1).Value

  • Wshell.SendKeys "{ENTER}"

End If

 

End Sub

 

 

 

 

Re: SAP GUI Script Development tool on Windows 7 and SAP GUI 7.30

$
0
0

Thanks Rahul. Too bad SAP has decided to disabled it. It used to save me so much time.

Re: Focus on SAP window using VBA

$
0
0

Hi Manuel.

For me the Scriptman solution works like this:

**************************************************************

Set Wshell = CreateObject("WScript.Shell")

Do

bWindowFound = Wshell.AppActivate("Import file")

wshell.run "c:\temp\1000.vbs",1,true

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("Import file")

if (bWindowFound) Then

Wshell.appActivate "Import file"

wshell.run "c:\temp\100.vbs",1,true

Wshell.sendkeys "{ENTER}" - I experimented with Enter here, without it, the path for file was inserted into browsing tab of "import file" window   

Wshell.sendkeys "c:\TEMP\TZK.PDF" - Here your URL

Wshell.sendkeys "{ENTER}"

end If

***************************************************************

This is some xxx.vbs file content and the file it must be run when the import window is active. The rest of the SAP script should be ok.

 

For trsctn CO02, script looks very similar like yours:

 

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").Text = "co02"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").Text = Range("G6").Value
session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/titl/shellcont/shell").pressButton "%GOS_TOOLBOX"
session.findById("wnd[0]/shellcont/shell").pressContextButton "CREATE_ATTA"
Set Wshell = CreateObject("WScript.Shell")
Wshell.Run "c:\temp\xxx.vbs", 1, False - im running before the window popup, because sometimes it went wrong, when the window wasnt fully loaded.
session.findById("wnd[0]/shellcont/shell").selectContextMenuItem "PCATTA_CREA"

 

session.findById("wnd[0]/shellcont").Close
session.findById("wnd[0]/tbar[0]/btn[11]").press

Kill "C:\TEMP\TZK.pdf"

Re: Focus on SAP window using VBA

$
0
0

Good afternoon Miroslav
First I want to thank you for responding
this is all very new to me
and also do not understand English, I only speak Spanish


I read your instructions and still confused
I have to do some tests
Tomorrow, 2/13/2014, I will try to test the script with the changes you
indicate
I'll tell you what happens with your instructions
Looking forward to solve this issue with the valuable support of this forum

It would be really useful for my daily job in terms of saving time
regards from a rainy Madrid

Re: Focus on SAP window using VBA

$
0
0

Good afternoon Miroslav

I followed your instructions. I have advanced a bit in my macro but I still have doubts

what I've learned and my new questions are:

have a main macro in a VBA module and have a helper script in VBS file

the macro immediately after the

 

"session.findById ( " wnd [0 ] / shellcont / shell " ) .pressContextButton " CREATE_ATTA "

 

statement calls the script to capture the URL of the file to attach to SAP

I have tried several times in succession and does not work in all cases . always does not work because the script does not select default button " Escritorio /Desktop"


Captura.JPG

Is it possible to select it somehow ?

If we solve the above I will always be attached to at least one SAP client file whose URL is written in the script. That would be a breakthrough and

But
on my list in Excel I have several SAP clients and I have to attach a different file for each. I would do it in a loop

This file would have the numbers of the SAP customers in a cell and another of the same row the URL of the file you want to attach

How I can make the script supports a loop over the file SAP customers that I have on my list of Excel?

Is it possible to merge the macro instructions with the instructions in a single set script to do the loop I need?

I hope I explained well .

Thank you

 

Macro VBA

............

Set Wshell = CreateObject("WScript.Shell")

Wshell.Run"C:\Users\MANUEL\Desktop\Script1.vbs", 1, False

............

Script1.vbs

Set Wshell = CreateObject("WScript.Shell")

Do

bWindowFound = Wshell.AppActivate("Importar fichero")

WScript.Sleep 1000

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("Importar fichero")

If (bWindowFound) Then

Wshell.AppActivate "Importar fichero"

WScript.Sleep 1000

Wshell.SendKeys"{ENTER}"

WScript.Sleep 1000

Wshell.SendKeys "C:\Users\MANUEL\Desktop\Sin titulo.png"

Wshell.SendKeys"{ENTER}"

End If

Re: Focus on SAP window using VBA

$
0
0

Hi.

I think the loop will be the last step. It will be just excel.

We need to solve it for 1 user. I dont fully understand (BTW im from Czech...we lost with Sweden) what you exactly need to add as an attachment. Why do you need to be on desktop as default? If you adding full path it doesnt matter where you actually are on the disc- desktop, C:\ ... you adding: Wshell.SendKeys "C:\Users\MANUEL\Desktop\Sin titulo.png". You want attach URL or file from disc?


Moreover I think that when I added pause like WScript.Sleep 1000 in script1.vbs, it didnt work. Do it like another file a and run it in script1.vbs like in my (scriptman) method , so we know we are on the same wave.


As I said try to remove enter before Wshell.SendKeys "C:\Users\MANUEL\Desktop\Sin titulo.png" play with it, see whats it doing during script running.

As I understand - In the end you will have user id in column A and URL link in column B. When you run vba, it will add attachment to user id in -SAP, jump on another user in col A and so on. Tomorrow I try access into trsctn you are using.


How to Count the Rows of a GUI Label Object

$
0
0

Hi,

 

I was wondering if anyone has any experience working with the GUI Label Object.  I'm able to navigate through it's rows by referring to the labels like this:

 

lblWBS = session.findById("wnd[1]/usr/lbl[1," & i & "]").Text

 

where i is a variable in a For Next loop.  In the example code above where i = 1, lblWBS would render "WBS Element"; when i = 3 lblWBS renders "121476.01.01.01.013533A, etc.  The narrow space between 1 and 3 is actually a label too so I assume it would be label 2.  You can see the example below. I also attached the .png file just in case you can't read the image I inserted.

 

GUI LBL.png

 

I need to be able to count the rows in this collection of lablel objects, or probably more accurately, count the labels in one colum.  I'm able to do this easily in a ALV grid but not in the GUI Label Object container.  Does anyone out there have any knowledge on this?


Re: Focus on SAP window using VBA

$
0
0

Hello Miroslav

I completely agree
First, we solve the macro for a single user / client SAP
The latter will fix the loop to multiple users / clients SAP

Sorry, I have not explained clearly ....
I want to add to each SAP client as an attachment is a file from disc to disc through its path
A file can be Word , Excel, Outlook, etc.

Indeed, I do not needto havethe default desktopto attach afile ona disk
I justneed to selectthemacrothatcontinuallygaveme errors.
Afteryourlast statementIthink theerrorsare related to the"{ENTER}" statement andinstructionstimeouts "Wscript.Sleep 1000"

But do notknow how toaffectthemacro script1andboth the locationof the instructionas
the number of
times you haveto include it  notknow howthe instructionsaffectwaiting times
"Wscript.Sleep 1000"

I tried to include the script code in a VBA macro and run it with open "Insert file " window. The
macro has worked every time I've tried ( about 20 times ) . I used the formula given by Scriptman four " time-outs " of the type:

 

waitTill = Now() +
TimeValue("00:00:01")

While Now() < waitTill

DoEvents

Wend

 

The macro does not support the formula " Wscript.Sleep 1000". Gives an "error 424 runtime . An Object Required "

I have run the script individually with open "Insert File " window and almost always works . In this case I've also included four ' waiting times " with the formula" Wscript.Sleep 1000 " because the proposed" waitTill = Now ( ) + TimeValue ( " 00:00:01 " ) - While Now () < waitTill - DoEvents - Wend " fails

It can be deduced that the script is correct

The problem is when I throw the main macro. When you reach the order to drop the " wshell.Run " script C : \ Users \
MANUEL \ Desktop \ Script1.vbs ", 1, False " NOT ALWAYS includes the path expected in the field "Name " and other instructions the script tries to open another session of SAP , the macro fails and remains in suspense

I do not know what happens .

It seems the time of opening time window "Insert file" or delayed will advance when the weather wshell includes data path

Is it possible to be adjusted in time by lengthening or shortening them script ?

I think we are very close to solving this, I hope you can help me

I have a question , what does the number "
1 " and the word "False" in the statement: wshell.Run "C: \ Users \ MANUEL\

Desktop \ Script1.vbs ", 1, False ?


Finally ,

Indeed , my idea is to have a customer number in column A and the file to attach in column B as in Example

Captura.JPG

Iindicatedthe twoways I've tried the script1. The first as amacroand the secondas ascriptactivatedby double-clickingin both casesthe "Insertfile"window was open.

Youalsoindicated thecompletemacro

I appreciatetheeffort and timeyou areinvesting in this.Is itpossible to scoreyourcontribution
to the forum, how is it done?

I take ityou likeice hockey

Greetings andgood weekend

 

MACROto run theScript

 

Sub insertando_archivo_en_la_ventana_de_Importar_archivo()

Set wshell = CreateObject("WScript.Shell")

Do

bWindowFound = wshell.AppActivate("Importar fichero")

waitTill = Now() + TimeValue("00:00:01")

While Now() < waitTill

DoEvents

Wend

Loop Until bWindowFound

bWindowFound = wshell.AppActivate("Importar fichero")

If (bWindowFound) Then

wshell.AppActivate "Importar fichero"

waitTill = Now() + TimeValue("00:00:01")

While Now() < waitTill

DoEvents

Wend

wshell.SendKeys "{ENTER}"

waitTill = Now() + TimeValue("00:00:01")

While Now() < waitTill

DoEvents

Wend

wshell.SendKeys "C:\Users\MANUEL\Desktop\Sin titulo.png"

waitTill = Now() + TimeValue("00:00:01")

While Now() < waitTill

DoEvents

Wend

wshell.SendKeys "{ENTER}"

waitTill = Now() + TimeValue("00:00:01")

While Now() < waitTill

DoEvents

Wend

End If

End Sub

-------------------------------------------------------------------------------------------------------------------------------------

Script

 

Set Wshell = CreateObject("WScript.Shell")

Do

bWindowFound = Wshell.AppActivate("Importar fichero")

wscript.sleep 1000

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("Importar fichero")

if (bWindowFound) Then

Wshell.appActivate "Importar fichero"

wscript.sleep 100

wshell.SendKeys "{ENTER}"

wscript.sleep 100

Wshell.sendkeys "C:\Users\MANUEL\Desktop\Sin titulo.png"

wscript.sleep 100

Wshell.sendkeys "{ENTER}"

end If

 

MYMAINMACRO

 

Sub intentando_anexar_documentos_en_SAP_dos()

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

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").Text = "/NCIC0"

session.findById("wnd[0]").sendVKey0

session.findById("wnd[1]/usr/lbl[22,4]").SetFocus

session.findById("wnd[1]/usr/lbl[22,4]").caretPosition = 3

session.findById("wnd[1]").sendVKey2

session.findById("wnd[0]/usr/sub/1/tabsCCONT_CONTROL/tabpCCONT_TAB01/ssub/1/1/2/sub/1/1/2/1/txt[1]").Text= "10591671"

session.findById("wnd[0]/usr/sub/1/tabsCCONT_CONTROL/tabpCCONT_TAB01/ssub/1/1/2/sub/1/1/2/1/txt[1]").SetFocus

session.findById("wnd[0]/usr/sub/1/tabsCCONT_CONTROL/tabpCCONT_TAB01/ssub/1/1/2/sub/1/1/2/1/txt[1]").caretPosition = 8

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[1]/usr/lbl[1,3]").caretPosition = 2

session.findById("wnd[1]").sendVKey 2

session.findById("wnd[0]").sendVKey0

session.findById("wnd[0]/usr/sub/1/tabsCCONT_CONTROL/tabpCCONT_TAB01/ssub/1/1/2/btn[2]").press

session.findById("wnd[0]/titl/shellcont/shell").pressButton "%GOS_TOOLBOX"

session.findById("wnd[0]/shellcont/shell").pressContextButton "CREATE_ATTA"

 

Set wshell = CreateObject("WScript.Shell")

wshell.Run "C:\Users\MANUEL\Desktop\Script1.vbs", 1, False

 

session.findById("wnd[0]/shellcont/shell").SelectContextMenuItem "PCATTA_CREA"

session.findById("wnd[0]/shellcont").Close

 

Set SapGuiAuto = Nothing

Set application = Nothing

Set connection = Nothing

Set session = Nothing

End Sub

Re: How to Count the Rows of a GUI Label Object

$
0
0

So where is your problem ?

 

in the Caption of the  Dialog is allready announced how much Records were found-

 

so you can easily do it like this:

a = Split(session.findbyid("wnd[1].text"), " ")    For i = 0 To UBound(a)        If IsNumeric(a(i)) Then            zählebis = CInt(a(i))            Exit For        End If    Next i     
For i = 3 to zählebis+3    lblWbs = session.findbyid("wnd[1]/usr/lbl[1,"&i&"]").Text
next i

Re: How to Count the Rows of a GUI Label Object

$
0
0

Brilliant!

 

I guess my problem was that I didn't even think of using the number in the Dialog caption.   I like the way you used the array to detect the numeric characters. I would have looped through all characters until I found the numeric ones; but I like your way better.

 

To get your code to work I had to Dim the array first in line 01, relocate a quotation mark in line 03 and add spaces around the ampersands and variable in line 11.

 

Dim a() As String    
a = Split(session.findbyid("wnd[1]").Text, " ")
For i = 0 To UBound(a)    If IsNumeric(a(i)) Then        zählebis = CInt(a(i))        Exit For    End If
Next i
For i = 3 To zählebis    lblWBS = session.findbyid("wnd[1]/usr/lbl[1," & i & "]").Text
Next i

Re: How to Count the Rows of a GUI Label Object

$
0
0

Gary Michalske wrote:

 

Brilliant!

 

I guess my problem was that I didn't even think of using the number in the Dialog caption.   I like the way you used the array to detect the numeric characters. I would have looped through all characters until I found the numeric ones; but I like your way better

.

Sometimes life can be so easy ;-)

 

 

To get your code to work I had to Dim the array first in line 01, relocate a quotation mark in line 03 and add spaces around the ampersands and variable in line 11.

 

  1. Dim a() As String 
  2.      
  3. a = Split(session.findbyid("wnd[1]").Text, " ") 
  4. For i = 0 To UBound(a) 
  5.     If IsNumeric(a(i)) Then 
  6.         zählebis = CInt(a(i)) 
  7.         Exit For 
  8.     End If 
  9. Next i 
  10. For i = 3 To zählebis 
  11.     lblWBS = session.findbyid("wnd[1]/usr/lbl[1," & i & "]").Text 
  12. Next i 

 

for sure - I wrote without any SAP (just out of my head)

 

gretings Thomas

Re: How to Count the Rows of a GUI Label Object

$
0
0

10-4.  Gottcha.

 

One other thing to note that will help others trying to do this is that the number in the Caption text is the count of the actual values (I know becuase I actually took the time to count them in SAP) and doesn't include the header row (1) and the space below it (2).  Because of this I had to remove the "+3" in line 9 in your code.

 

Nonetheless...thanks a lot Thomas!

Re: Focus on SAP window using VBA

$
0
0

Hi.

Hockey is not for me, Ijust had fortuna ticket... and I lost...

Now, I do not have permission for transacvtion, you are using so I dont know how it exactly work.

The  False after run command is for wait to complete command I think, 1 dont know.

Now for the key problem:

 

As I said: Do it exactly like in my solution:

Excel Vba is correct.

Create 3  files in c:\temp -for example:

 

1.

Script1.vbs - inside file is:

 

Set Wshell = CreateObject("WScript.Shell")

Do

bWindowFound = Wshell.AppActivate("Import file")

wshell.run "c:\temp\1000.vbs",1,true

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("Import file")

if (bWindowFound) Then

Wshell.appActivate "Import file"

wshell.run "c:\temp\100.vbs",1,true

Wshell.sendkeys "{ENTER}" 

Wshell.sendkeys "c:\TEMP\TZK.PDF" - Here your document path

Wshell.sendkeys "{ENTER}"

end If

 

2.

1000.vbs- inside file is:

wscript.sleep 1000


3. - I think this is optional, you can use 1000 everywhere, but now do it.

100.vbs

- inside file is:

wscript.sleep 100


-The use of wait method is probably crucial here!!!


VBA:

......

session.findById("wnd[0]/shellcont/shell").pressContextButton "CREATE_ATTA"

 

Set wshell = CreateObject("WScript.Shell")

wshell.Run "C:\temp\Script1.vbs", 1, False

 

session.findById("wnd[0]/shellcont/shell").SelectContextMenuItem

.......

And THEN we can discus errors...


I have it now like - when i open excel document it creates these 3 files when opening. Before close - they are deleted.

Im pretty sure we are stuck on the time delay here.


Re: How to Count the Rows of a GUI Label Object

$
0
0

Thomas,

 

I was wondering if its possible to use a For Each loop to read all of the labels instead of trying to count them.  The labels do seem to be part of a collection but I can't seem to get it to work.  Here is what I see in the SAP Scripting Help file:

Lbl Object Model.pngLabelCollection.png

LblCollectionProperty.png

 

Do you have any idea on how to construct a For Each Loop with the above information?


SAP GUI Appearance Changes After VBScript Manipulation

$
0
0


I can't seem to find any posts on this issue in the forum; perhaps someone out there knows how to fix this via VBScript.

 

I have an Excel macro that manipulates SAP via embedded VBScript. The script was recorded using the SAP Script recorder.  After the code has run, the GUI appearance for popups (session.findById("wnd[1]) forms and subsequent forms look different and less user-friendly. The original session.findById("wnd[0] appearance seems unaffected and looks fine.  Is there a way to ensure that the original, default appearance for session.findById("wnd[1] is maintained after manipulating SAP via VBScript?  The only way I found so far is to log out of the SAP GUI

 

Example:

 

After drilling down to find a WBS code by clicking the drop down icon indicated below:

 

PopUpVBS.png

 

The subforms (popups - session.findById("wnd[1]) look like the screenshots below (before and after):

 

Before Running Script (every day user look and feel):

 

BeforeVBS.png

 

After running script:

 

AfterVBS.png

Re: SAP GUI Appearance Changes After VBScript Manipulation

$
0
0

At the end of your script, did you clear the object variables by assigning it to Nothing? i.e.

 

set session = nothing

set connection = nothing

 

etc?

Re: How to Count the Rows of a GUI Label Object

$
0
0

The solution to get the number of row is brilliantly simple.

 

However, I don't think the lblWBS for-loop will work until the last row. I suspect that halfway through the loop, the script will throw the cannot find by id error.

 

If my suspicion is wrong, do tell.

Re: Tips and Tricks: SAP GUI scripting object hierarchy view

GuiXT Copytext or VBScript - not allowing to paste values to multiple selection

$
0
0

Hello Guru's of Scripting.

We have a requirement to download inspection lot information for 4500+ plants using transaction QA33. We cannot use all plants at a time to get result output. I would like to run this report in parts. example: 20 plants at a time.

QA33 screen with plant selection:

2-19-2014 9-17-06 AM.jpg

Multiple selection for plant:

2-19-2014 9-18-01 AM.jpg

 

Here is my code so far:

_______________________________________________________________________________________________________________________________**********************************************************************************************************************************************************************************

//Counter

Set V[i] 1

//Input file that contains more than 4500 plants

Parameter mat_file1 "C:\Documents and Settings\Desktop\ip2.txt"

//Intermediate file to copy 20 plants at a time

Parameter mat_file3 "C:\Users\Desktop\myfile.txt"

 

 

//create myfile.txt text file on C:\Users\Desktop\ location before running program

  OpenFile "&U[mat_file3]" -Output

  OpenFile "&U[mat_file1]"

 

 

 

 

 

 

 

label Read_File

  ReadFile "&U[mat_file1]" C

 

 

if not Q[ok]

    CloseFile "&U[mat_file1]"

    CloseFile "&U[mat_file2]"

    CloseFile "&U[mat_file3]"

    Return "Job done!" "&U[mat_file1]"

  endif

 

 

// loops

//1st loop to make sure the total no of records do not exceed 4500

If V[i<4500]

AppendFile "&U[mat_file3]" C

Set V[i] "&V[i]" + 1

//Checking to make sure we append only 20 plants at a time.

//These 20 plants are added to myfile.txt

if V[i=21]

//myfile has 20 file it goes to transaction qa33 screen

Goto next_step

endif

goto Read_File

endif

 

 

 

 

 

 

label next_step

 

 

//Deletes default values from selection fields

Set F[%_QL_ENSTD_%_APP_%-TEXT] ""

Set F[%_QL_ENSTD_%_APP_%-TO_TEXT] ""

Set F[Plant] ""

Set F[Maximum No. of Hits] ""

 

 

 

 

// Inspection Lot Selection

Screen RQEEAL10.1000

//Clicked on multiple selection button

  Enter "=%043"       // Multiple selection.6

 

 

 

// Multiple Selection for Order

 

 

Screen SAPLALDB.3000

//This is equivalent to clicking on delete button from multiple selection

Enter "/16" //delete contents

 

 

// Multiple Selection for Plant

 

 

Screen SAPLALDB.3000

 

//Copy 20 plants from myfile to text t1

Copytext fromFile="&U[mat_file3]" toText="t1"

//Copy those 20 plants from t1 to clipboard

Copytext fromText="t1" -toclipboard

//Next step is to click on paste icon on dynamic selection

Enter "/24" //copy from clipboard

 

 

// Multiple Selection for Material

Screen SAPLALDB.3000

  Enter "/8"

 

 

// Inspection Lot Selection

Screen RQEEAL10.1000

  Enter "/8"       // Execute

 

// Display data for inspection lot: Worklist for Inspection Lots

Screen SAPLSLVC_FULLSCREEN.0500

  Enter "/Menu=1,4,3"       // Local file...

 

// Save list in file...

Screen SAPLSPO5.0110

  Set R[Spreadsheet] "X"

  Enter

 

// Display data for inspection lot: Worklist for Inspection Lots

Screen SAPLSFES.0200

  Set F[DY_PATH] "C:\Users\Desktop"

  Set F[DY_FILENAME] "temp.txt"

  Enter "/7"       // Extend

 

 

// Display data for inspection lot: Worklist for Inspection Lots

Screen SAPLSLVC_FULLSCREEN.0500

  Enter "/3"

 

 

Set V[i] 1

//OpenFile "&U[mat_file3]" -Output

Set V[t2] ""

Copytext fromText="t2" toFile="C:\Users\Desktop\myfile.txt"

// Display data for inspection lot: Worklist for Inspection Lots

 

 

CloseFile "&U[mat_file3]" -Output

 

 

 

 

 

 

//Screen SAPLSLVC_FULLSCREEN.0500

//  Enter "/nqa33"

goto Read_File

 

******************************************************************************************************************************************************************************____________________________________________________________________________________________________________________________

 

 

 

 

Problem part of the code:

 

Copytext fromFile="&U[mat_file3]" toText="t1"

 

Copytext fromText="t1" -toclipboard

 

Enter "/24" //copy from clipboard


When I debug this code ..I see empty value for t1 or clipboard.

I have tried several Copytext options but no solution so far.

Please help me with this issue.

GuiXT solution OR VBScript but I want it to be able to paste 20 values.

I really appreciate you'r time and effort in this regard.


SAP Krazy



Viewing all 1708 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>