Get the value of an output screen field - vba

In view of counting how many rows I have in my table, I usually export it via VBA in excel then count the rows. Is there any way to get it directly from SAP GUI?
I tried to get it by .VerticalScrollbar.Maximum, but unless I don't use it properly, it didn't give me the right number...
ScrollBar = session.findById("wnd[0]/usr").VerticalScrollbar.Maximum
MsgBox ("ScrollBar= " & ScrollBar)
In other words:
In this filed I have 316 rows (counted with the excel export); .VerticalScrollbar.Maximum gives me 267 rows. Where are the 49 rows left in my count ?
I also found out that that this "information" button make this window appear:
And these two numbers make the 316 I'm looking for: 395-79 = 316
So I tried to interact with this window while recording a macro and it only saves this interaction:
session.findById("wnd[1]/usr/sub/1[0,0]/sub/1/6[0,10]/sub/1/6/8[0,14]/lbl[28,14]").setFocus
session.findById("wnd[1]/usr/sub/1[0,0]/sub/1/6[0,10]/sub/1/6/8[0,14]/lbl[28,14]").caretPosition = 0
No way to copy these numbers...
Edit: clarifactions
Thanks for reading and have a good day!

session.findById("wnd[1]/usr/sub/1[0,0]/sub/1/6[0,10]/sub/1/6/8[0,14]/lbl[28,14]").text
Worked well.
#sandra-rossi : Thanks !

Related

Excel VBA - PivotItems returns inexesting value

In an Excel Workbook, I have "static" pivot table on a sheet, that is based on data from another sheet.
I'm refreshing the data on my data sheet (thank you captain Obvious !), then I want to show ALL the items, exept the blank one, so I'm running throw all the PivotItems to set them to visible, and, at the end, unselecting the blank one :
i = 1
ThisWorkbook.Sheets("TCD").PivotTables(i).PivotFields("CODETAT").ClearAllFilters
ThisWorkbook.Sheets("TCD").PivotTables(i).PivotCache.MissingItemsLimit = xlMissingItemsNone
For Each PvI In ThisWorkbook.Sheets("TCD").PivotTables(i).PivotFields("CODETAT").PivotItems
PvI.Visible = True
Next
ThisWorkbook.Sheets("TCD").PivotTables(i).PivotFields("CODETAT").PivotItems("(blank)").Visible = False
At the last occurs of my loop, on the 4th PivotItems, I have an error of execution '1004' (I'll translate it from french, it may me some errors, sorry) "Impossible to define the property Visible of the class PivoItem", so I checked a few things :
?ThisWorkbook.Sheets("TCD").PivotTables(i).PivotFields("CODETAT").PivotItems.count
4
for x = 1 to 4 :
?ThisWorkbook.Sheets("TCD").PivotTables(i).PivotFields("CODETAT").PivotItems(x)
(blank)
SFT
ACQ
TEP
It look like I have 4 items in my Pivot Table, but
And also, when I check my datas, I only have 2 different stats :
So where does this 4th PivotItems' element is coming from, and how can I get ride of it ?
Thank you.
I had a surprising issue like that, you need to check in the Pivot Table options :
Right click on the pivot table,
Select Pivot Table options
Go in Data tab
Find Retain items deleted from the data source
Choose None for Number of items to retain per field!
Then refresh! All should be OK now! ;)
(that thing drove me mad for hours!^^)

Development DropDowns List error on empty value

I have a simple dropdown list named DD8. It uses 50 rows as control, the problem is that for now only 45 rows are used. That means that in the dropdown list there are 5 empty rows. The problem is that if someone select one empty row, or don't select anything (default is empty) the fallowing code will show error :
With Worksheets(1)
NameProf = .DropDowns("DD8").List _
(.DropDowns("DD8").ListIndex)
End With
I tried things like if .DropDowns("DD8").List (.DropDowns("DD8").ListIndex) != "" but ofc, it shows error. I searched how to select only used rows with the DropDown list of the development tab but it doesn't seem to be possible.
I have to select 50 rows because new customers can be added.
Do you know how it can be achieved ?
If new customers can be added, then I imagine, and hope for you, that it goes above 50.... so it's not just an issue of having 5 blanks for now to not be an option, but also allowing customers 50-2,483 also be on there when they come along. ---- Without more details on your code, I believe this suggestion should help 'guide' you but not immediately solve your issue.
Essentially, whenever you call to have your dropdown populated, you want some code to find the last row of data in the customers column, and then assign your dropdown to populate with the starting row of your customers to the lastrow. This way no matter how many customers you have 2, 48, 189... they will show in your dropdown without that issue occurring. A simple google search will yield how to find the last row in excel.
Sorry I couldn't just bust out the code to make it work for you right this second, but I think this should be a good starting point for you.

Get the id of the selected value in a dropdown validation list on Excel in VBA

Using Excel, lets say I have a validation list made of 5 values like this one :
Patate
Tomate
Courgette
Concombre
Patate
In a cell containing a drop down list made of these 5 value, I select the fifth value : "Patate".
I want to get in VBA that this cell contains the 5th value of my validation list. Something like :
x = Cell.Validation.GetIDValueSelected
x = 5
I can't use Vertical search because I might have 2 or even more time the same value in my list (too long to explain why).
This list is also dynamics (depending of another sheets) so it doesn't always contains 5 values.
I hope I made it clear for everyone to understand my needs but I will be glad to add more information if needed.
Thank you for your time.
Sadly, once you have used DV to fill a cell with junk, there is no way to tell which piece of junk you picked:
You would have to pad each piece of junk with a different number of blanks.

How to move one column to the end in Pivot table with VBA?

I create a pirvot table, but the colunm order is not what I wanted. I want to move one column to right end. I can do it in Excel, but don't know how to do it with VBA.
In Excel, can do in this way--active the column header which you want to move, click right-hand button, choose Move, Move "--" to end.
Record Macro--when record Macro, it just shows the exact position, just like,
ActiveSheet.PivotTables("PivotTable16").PivotFields("wk").PivotItems("#VALUE!") _
.Position = 12
But I want to use the Macro in other files, maybe the end position is not 12. Then the Macro can't be used.
Hope can get help here. How to do it to move the colunm to end by VBA? Thanks.
I hope I get you right.
You can get the end position by
ActiveSheet.PivotTables("PivotTable1").PivotFields("whatever").PivotItems.count
Basically it returns the number of items for a label
Edited
So you could do like
Dim total as Integer
total = ActiveSheet.PivotTables("PivotTable1").PivotFields("whatever").PivotItems.count
ActiveSheet.PivotTables("PivotTable1").PivotFields("whatever").PivotItems("whatever").position = total
Just a random note to anyone that comes across this and runs into the same issue I did. If in your macro you're hiding fields, it's going to give you an error. Don't use this code as the last thing you do when setting up your pivot table. Use this code, let it move to the bottom position, THEN have your code to hide your fields. If you hide fields first, it'll count the hidden fields then try to move it outside your pivot table and cause an error.

Speeding up looping through a textfile in vbs

Good afternoon,
I have a problem with my code where im looping through a textfile. The textfile has approx 10,000 lines so I came up with using the instr search function to find the line number by finding the character number in which the "test name" appears and then using the mid function and counting left to find the line number.
eg.
000004###24503###Open Account Web ISA single###2#########Please enter your first name.###False#########Mr############callie####################################################################################################################################################################################################################################################################################################################################666###Imagenericpassword###Ops#######################################################################################################################################Cash ISA 2009 / 2010##########################################################################################################################################################################################################################################
So in this case it finds "Open Account Web ISA single" and counts left to find 000004. So this saves me looping through 10,000 lines.
So next I split this line into an array using ### as a delimeter, this results in lots of empty "columns" since they were empty when i concatinated the data from excel. This leaves me with a total of around 247 columns. My issue is I dont want to really loop through 247 columns since lots of them contain...well nothing. Is there a quicker way for me to do this?
I used to use excel but its far too slow.
You can remove the empty columns:
Set re = New RegExp
re.Pattern = "(###){2,}"
re.Global = True
withoutEmptyCols=re.Replace(input,"###")
This is the result for your example:
000004###24503###Open Account Web ISA single###2###Please enter your first name.###False###Mr###callie###666###Imagenericpassword###Ops###Cash ISA 2009 / 2010###