# How to Get the list of MenuBars in excel using ruby

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-list-of-menubars-in-excel-using-ruby/173927>\
**Category:** Ruby\
**Created:** [August 18, 2009, 10:57am UTC](https://www.ruby-forum.com/t/how-to-get-the-list-of-menubars-in-excel-using-ruby/173927 "2009-08-18T10:57:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vamsi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b38774/32.png) [@vamsi](https://www.ruby-forum.com/u/vamsi)\
**Post date:** [August 18, 2009, 10:57am UTC](https://www.ruby-forum.com/t/how-to-get-the-list-of-menubars-in-excel-using-ruby/173927/1 "2009-08-18T10:57:56Z")

</div>

Hi,

i’m trying to get the list of menubars in the excel using ruby  
i can able to get the menubars count but unable to get the list of menu  
bars.

my idea is to get the list of menubars and click on a perticular menu  
bar item.

my code is:

require “win32ole”  
excel=WIN32OLE.new(“Excel.Application”)  
excel.visible=true  
workbook = excel.Workbooks.Add  
excel.DisplayAlerts = false  
puts excel.MenuBars.ole\_get\_methods  
puts excel.MenuBars.count(\* Here i can get the count.)  
excel.Quit

Thanks  
Vk.

---

<div class="post-metadata">

**Author:** ![vamsi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b38774/32.png) [@vamsi](https://www.ruby-forum.com/u/vamsi)\
**Post date:** [August 18, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/how-to-get-the-list-of-menubars-in-excel-using-ruby/173927/2 "2009-08-18T15:15:19Z")

</div>

Vamsi K. wrote:

> Hi,
> 
> i’m trying to get the list of menubars in the excel using ruby  
> i can able to get the menubars count but unable to get the list of menu  
> bars.
> 
> my idea is to get the list of menubars and click on a perticular menu  
> bar item.
> 
> my code is:
> 
> require “win32ole”  
> excel=WIN32OLE.new(“Excel.Application”)  
> excel.visible=true  
> workbook = excel.Workbooks.Add  
> excel.DisplayAlerts = false  
> puts excel.MenuBars.ole\_get\_methods  
> puts excel.MenuBars.count(\* Here i can get the count.)  
> excel.Quit
> 
> Thanks  
> Vk.

The MenuBars collection is not intended for use through the API.

You’ll want to access the Worksheet Menu Bar via the CommandBars  
collection:

menubar = excel.CommandBars(“Worksheet Menu Bar”)

The following simple example iterates over the “Worksheet Menu Bar”  
CommandBar and prints out the name of each top menu and its menu items:

menubar.Controls.each do |menu|  
puts(“MENU: #{menu.Caption}”)  
menu.Controls.each do |control|  
puts("\t#{control.Caption}")  
end  
end

I hope that helps. I can perhaps provide more detail later.

David

---

<div class="post-metadata">

**Author:** ![vamsi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b38774/32.png) [@vamsi](https://www.ruby-forum.com/u/vamsi)\
**Post date:** [August 19, 2009, 9:09am UTC](https://www.ruby-forum.com/t/how-to-get-the-list-of-menubars-in-excel-using-ruby/173927/3 "2009-08-19T09:09:15Z")

</div>

Thank you David, its working.  
can you please send some links or additional information for clicking  
the menubars and menus in the Excel using ruby.

Thanks  
Vk.
