How to Get the list of MenuBars in excel using ruby

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.

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs