The clue are the two commands
FrontEndTokenExecute[nb, "ExpandSelection"]
FrontEndTokenExecute[nb, "SelectionOpenAllGroups"]
However, one has to re-apply the method mentioned in my initial post once more after these two commands.
Sample Select Last Celle Programatically.nb
nb = EvaluationNotebook[];
SelectionMove[nb, All, Notebook] (* \
this one selects all cells in this notebook *)
SelectionMove[nb, After, Cell] \
(* this one moves the insertion point below everything *)
SelectionMove[nb, Previous, Cell,
AutoScroll ->
True] (* if the last cell is part of a closed group, the selection stays \
invisible *)
FrontEndTokenExecute[nb, "ExpandSelection"] (* this one \
selects the group enclosing the last cell *)
FrontEndTokenExecute[nb, "SelectionOpenAllGroups"] (* this one opens it *)
\
SelectionMove[nb, After, Cell] \
(* like command 4 steps above, this one moves the insertion point below \
everything *)
SelectionMove[nb, Previous, Cell,
AutoScroll ->
True] (* now it is no longer part of a closed group, therefore it becomes \
visible *)
10 outmost group: Several groups are stacked one ontop the next. All cells groups are closed individually. This is a test case for the program above.
9 intermediate group
8 intermediate group
7 intermediate group
6 intermediate group
5 intermediate group
4 intermediate group
3 intermediate group
2 intermediate group
1 innermost group
f /@ Range[3]
{f[1], f[2], f[3]}
(I had this all in a notebook but I found no way to upload it... After copying all this to a notebook, set everything to manual grouping and then nest the cells from the last one one after the other with the next line above it and then close all subgroups.)
The attached notebook shows how it has to be done and it also contains a test example of deeply nested groups of cells at the very end to which the selection goes. However, a proof that this always works and never fails is still missing, since I have neither an "axiomatic" description of ExpandSelection nor of SelectionOpenAllGroups.
I wish there were more links "also see" in the Help system, especially whrer it is about FrontEnd-related functions.