I am able to enter to the operation in SAP GUI via VBA but I am unable to find how to select or copy the value of these fields.
While recording the script via SAP GUI, copying the fields into the clipboard won't appear in the script as an action.
Any help or reference is highly appreciated.
Please find code and screenshot below (screen of type "ABAP List").
Sub XXXX()
Call SAPConnections
Session.FindById("wnd[0]/tbar[0]/okcd").Text = "Operation"
Session.FindById("wnd[0]").SendVKey 0
Session.FindById("wnd[0]/usr/ctxtP_MATRL").Text = "PartNumber"
Session.FindById("wnd[0]").SendVKey 8
Session.FindById("wnd[0]/tbar[1]/btn[1]").Press
The screen you are showing is named an "ABAP List".
It contains labels and text fields, they belong to the property Children of the GuiUserArea object, and their IDs are made of prefix lbl or txt followed by the column and row numbers. The respective SAP GUI Scripting objects are GuiLabel and GuiTextField, for example:
label at column 0 (first column) row 12 (object GuiLabel):
/app/con[0]/ses[0]/wnd[0]/usr/lbl[0,12]
text field at column 22 row 12 (object GuiTextField):
/app/con[0]/ses[0]/wnd[0]/usr/txt[22,12]
checkbox at column 0 row 0 (first row) (object GuiCheckBox):
/app/con[0]/ses[0]/wnd[0]/usr/chk[0,0]`
If you want to know all the fields which are in the ABAP list, you must loop at the property Children of the GuiUserArea object.
EDIT: checkbox added in the list above. I think we now have all the possible types of fields for an ABAP List (I guess other simple graphical elements objects like GuiButton, GuiComboBox, GuiCTextField, GuiRadioButton, are not possible).
EDIT: see this more detailed answer with a script to loop at all ABAP List fields and example with a screen and corresponding property values.
Related
I am a complete VBA beginner and this is the first time I have had to deal with VBA. My project is simple- a user form which heavily relies on dependent drop down lists. I watched a ton of videos and wrote (more like copy-pasted) code which actually works just fine. My issue is that I need to edit part of my code to add a feature which I have trouble finding a video on (trial and error editing only took me this far).
In it's current state, my form has two dropdown lists drawing information from a sheet where data is arranged in columns as follows:
ITEM ID | ITEM | CATEGORY
The user picks a category and then the item list if filtered based on the previous selection. I now need to rearrange those columns are add another one, making it the 1st tier selection as follows:
LOCATION | CATEGORY | ITEM ID | ITEM
Just rearranging the columns alone breaks my code. On top of that I need to add the Location combobox, which would filter the Categories, which in turn filter the Items.
This is the code which handles the CATEGORY and ITEM list:
Private Sub cmbEquipCategory_Change()
Dim sh As Worksheet
Dim lastBlankRow As Long
Me.cmbEquipment.Clear
Set sh = Sheets("Equipment_List")
lastBlankRow = sh.Cells(Rows.Count, 3).End(xlUp).Row
For i = 2 To lastBlankRow
If sh.Cells(i, 3) = Me.cmbEquipCategory.value Then
Me.cmbEquipment.AddItem sh.Cells(i, 2)
End If
Next i
End Sub
It is my impression that I need to alter this code to draw data from columns 2 and 4 (it currently does so from 3 and 2) and write another almost identical block of code which handles LOCATION and CATEGORY. Any advice, resources or help would be greatly appreciated. Thanks!
The way I do this is to used named ranges. So selecting your ITEM ID would lead to one of several ITEM ranges (I name them according to the ITEM ID options) which would lead to one of several CATEGORY ranges (I name these according to the ITEM options). The more options you have the more ranges you need. Named ranges aren't broken by adding in columns.
I have a vba Array of items in column 1 and items they feed in column 2.
I want to have a clean visual way to illustrate a "branching" effect on the spreadsheet but I'm at a loss on what the best method would be.
So this question is more of "What is the best method to use" kinda thing.
Just to visualize though, let's say my array looks like this:
(Col1 and Col2 separated by a space)
Array1:
PowerStrip1 TV
PowerStrip1 DVDPlayer
PowerStrip2 Soundbar
I want to have them look something like this on the excel spreadsheet:
PowerStrip1
|---> TV
|---> DVDPlayer
PowerStrip2
|---> Soundbar
Perhaps not the neatest way of showing it but you get the just. What would be the best method of achieving this look in a clean way?
Pivot Table is your friend in this. Select your data range then insert Pivot Table and arrange like below screenshot.
Unable to comment on #Harun24HR, so adding this as new answer
After creating a pivot table as mentioned by #Harun24HR, Try the following
In pivot table fields, click on the drop down available in Items field and select field setting. This will open a pop up
On subtotals & filters, select radio button besides "None"
Now go to layout & print
Have the radio button beside "show items label in outline form checked
Now and untick the check box below them
I believe this will give the desired result
Thanks guys, Harun24HR provided a perfectly good solution but I also wanted to share a different solution I came up with that displayed the information in more of a Tree-View format just in case it helps anyone else.
Lets say the Sheet name is "Summary", and the range of information to be used is A2:B200.
Assume the "Parent" information is in column "A" and the "Child" information is in column "B".
Also, you need to go to the Developer Tab -> Insert -> Active X Controls -> More Controls -> Microsoft TreeView Control, version 6.0. This is the TreeView control which will show our information.
I changed the name of the TreeView control to "tv" for simplicity.
See code below:
Sub TreeViewStuff()
'Using TreeView Nodes to populate the power sources summary
'Clear pre-existing nodes
Dim arr as variant
Dim str as string
Dim i as integer
On Error Resume Next
Sheets("Summary").tv.Nodes.Clear
'Copy range into an array
arr = Sheets("Drop Downs").Range("A2:B200")
'The first column of the array contains the parents, lets add them as keys
For i = 1 To UBound(arr)
str = ""
'Add the parent
Sheets("Summary").tv.Nodes.Add Key:=arr(i, 1), Text:=arr(i, 1)
'Expand the node
Sheets("Summary").tv.Nodes(Sheets("Summary").tv.Nodes.Count).Expanded = True
Err.Clear
Next i
'The second column will contain the kids, lets add them
For i = 1 To UBound(arr)
str = ""
'Add the kids
Sheets("Summary").tv.Nodes.Add arr(i, 1), tvwChild, arr(i, 2), arr(i, 2)
'Expand the node
Sheets("Summary").tv.Nodes(Sheets("Summary").tv.Nodes.Count).Expanded = True
Err.Clear
Next i
End Sub
The TreeView approach can give a "Dotted Line" illustration between the parent and child nodes which was something I wanted to show. Again thanks for the help!
I have a VBA form which is used to enter data on a sheet. I am currently coding the form so as it will load any data already existing in the sheet back into the form.
For simple text strings it works perfectly.
e.g.
ReqSetup.ReqText = Application.Worksheets("Req Sheet").Range("F11").Value
However, I have some combo boxes, that on the form, when they are selected will enter a number in the corresponding cell.
Fail 1. - Run Time Error 380 - Invalid property value.
ReqSetup.MinPerKgCB = Application.Worksheets("Req Sheet").Range("C27").Value
Fail 2.
Dim MinPerKg As Range
Set MinPerKg = Application.Worksheets("Req Sheet").Range("C27")
ReqSetup.MinPerKgCB = MinPerKg
I'm obviously doing something really simple wrong but I can't work out what it is!!
Kind Regards!
I have some combo boxes, that on the form, when they are selected will
enter a number in the corresponding cell
Then you'd need to do the opposite of your code attempt, i.e.:
Worksheets("Req Sheet").Range("C27").Value = ReqSetup.MinPerKgCB.Value
That you'd better wrap inside a check that any combobox value is actually selected :
With ReqSetup.MinPerKgCB
If .ListIndex <> -1 Then Worksheets("Req Sheet").Range("C27").Value = .Value
End With
I've got an issue with my listbox. In the user form initialize event I'm using the following code to populate it:
RecordSelectionBox.List = WorkingCopy.Worksheets(1).Range("A2:P20").Value
Which works out fine. I have column width adjustments which also work out fine. Once the user has selected a record, a line from the listbox I'm setting the captions of a bunch of labels to the value of the listbox columns. It fills out label captions 1 to 15 just fine. When it hits 16 I get an error "Could Not Get the Column Property. Invalid Argument" "Run-time error '-2147024809 (80070057)'"
Here is the code:
Explanation.Caption = RecordSelectionBox.Column(16)
a debug.print of RecordSelectionBox.ColumnCount shows that I indeed have 16 columns. The explanation field is the longest of the fields I'm using, but I'm not sure that I see how that would become an issue. If anyone has an idea, I'm all ears.
That is because the First Column of the listbox starts with 0
Your first Label should be
Label1.Caption = RecordSelectionBox.Column(0)
and the 16th should be
Explanation.Caption = RecordSelectionBox.Column(15)
I am trying to write an Excel VBA script to navigate to a website and select from a drop-down list using the text in the list item, NOT the value of the index. By examining the HTML code, I can see that the values in the drop-down list appear to be integers with no recognizable pattern and do not appear to correlate to the text shown for the entry in the drop-down list.
<option value="246">new2</option>
<option value="245">new</option>
<option value="196">test</option>
I can successfully use the following command:
ieDoc.getElementById("viewMaintainFixedCombustible_fixedCombustible_fireZoneId").Value = 246
To select the item "new2" from the drop-down list, by sending the value 246. Or, I could send 245 to select "new". However, the elements in the list are always changing, so selecting by value (246, 245, etc.) is impractical. Thus, I am searching for a way to select an entry from the drop-down list (e.g. "new2") by sending the text name of the entry (e.g. "new2") in VBA.
Does anyone have a method for how to do this?
Try below sample code to set dropdown list by text.
Set drp =ieDoc.getElementById("<id of your dropdown>")
For x = 0 To drp.Options.Length - 1
If drp.Options(x).Text = "new2" Then
drp.selectedIndex = x
Exit For
End If
Next