How to programmatically open or close an Excel grouping pane

Hello, I am developing a class around the Excel object and I would like to expand/close a group of rows or columns programmatically...

Everything that I have tried using the ShowDetail property did not succeed so far and the ActiveSheet.Outline.ShowLevels method either expand or close a specific group placed of grouped row(s) or column(s).
Unfortunately, the Excel macro recorder does not record the action performed when clicking the [+] grouping pane button...

Could anyone give me a pointer or an example of how to programmatically open or close an Excel grouping pane?
LVL 4
VorenusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sstampfCommented:
Hi,
You can use the code which I have provided in the sample below. Let me know if you have any questions/concerns.
Thanks
Shashank

sample-Group-Ungroup.xls
0
sir plusSales ManagementCommented:
use Outline.ShowLevels Method
0
sstampfCommented:
I am sorry sirplus but I have posted the same solution almost 20 min before you.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

VorenusAuthor Commented:
Thanks a lot for your answers.
Unfortunately not exactly what I am after. What I am looking for is to open/close a particular group, rather than all the ones belonging to a particular level at once.

If I'm not clear, please do not hesitate to let me know.

Thanks again.
0
folderolCommented:
If you assign a summary row in a group to a range, you can use the showdetail property to hide / unhide the child rows for that summary.  I make the summary subtotal the top row, this makes the toggling hide / unhide more appealing. From the snippet, you can see I'm just hardcoding in the row number (18).  The Showdetail property is false if even one row in the group is hidden, so the use of the NOT function as
    tcode.ShowDetail = Not tcode.ShowDetail  
(if its currently false, set to true, if its currently true, set to false)
may not be always reliable, it will depend on your user not hiding rows and columns manually.

Attached is a workbook I did on EE about a year ago for another question.  It demos the working code.

Tom.

Private Sub CommandButton1_Click()
    Dim tcode As Range
    Set tcode = Rows(18)
    tcode.ShowDetail = Not tcode.ShowDetail    
End Sub

Open in new window

Proj-Tracking-Xpert.xls
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VorenusAuthor Commented:
Thanks a lot folderol, it is exactly what I was looking for, the code works great!!
I gave 50 points to sstampf to thank him for his effort anyway, I hope you don't mind...

Thanks again.
0
folderolCommented:
I don't mind at all, glad I could help. Odd how macro recording works / doesn't work, isn't it?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.