WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Enumerating Excel Commandbar Controls


;///////////////////////////////////////////////////////////////
; Winbatch - Enumerating Excel Commandbar Controls            //
;            2004B - Excel 2002                               //
;                                                             //
; Along the way, playing with a controls Execute() method     // 
; and thinking about WB possibilities for custom controls     //
;                                                             //
; stan littlefield - May 18, 2004 - please retain this header //
;///////////////////////////////////////////////////////////////
path = Filepath( IntControl(1004,0,0,0,0) )
oXL                  = CreateObject("Excel.Application")
oXL.Visible          = @FALSE      
oXL.UserControl      = @TRUE
oXL.DisplayAlerts    = @FALSE
oXL.ScreenUpdating   = @TRUE     
cFile = StrCat(path,"XLcBars.txt")
str = ""
txt = "Current Bar"
BoxOpen("Excel Command Bar Enumeration",txt)
isThere = @FALSE
ForEach cBar in oXL.CommandBars
   txt = cBar.Name
   v="Visible"
   If !(cBar.Visible) Then v="Not Visible"
   str = StrCat(str,"COMMAND BAR: ",txt," ",v,@CRLF)
   If txt =="Standard" Then isThere = @TRUE    ;not really needed
   ForEach ctl In oXL.CommandBars("%txt%").Controls
      BoxText( StrCat(txt,@CRLF,"   ",ctl.Caption) )
      str=StrCat(str,"   ",ctl.Caption,@CRLF)
   Next 
   str=StrCat(str,@CRLF)
Next

FilePut(cFile,str)
Drop(str)
BoxShut()
oXL.Visible = @TRUE
;test the Execute() Method - should perform a file Open or create New Sheet
;If isThere Then oXL.CommandBars("Standard").Controls("Open").Execute()
;or
If isThere Then oXL.CommandBars("Standard").Controls("New").Execute()
;I know you can use
;oXL.WorkBooks.Open() or oXL.WorkBooks.Add()
;but that is not the point   


oXL = 0
Exit
;/////////////////////////////////////////////////////////////////////////////

Article ID:   W16607
File Created: 2005:02:18:12:21:36
Last Updated: 2005:02:18:12:21:36