Is there a key binding for the toolbar button?
If there is, you can use the SendKeys method to send this key to Excel: http://msdn.microsoft.com/en-us/library/aa202943(office.10).aspx
Alternatively, the CommandBars collection may be useful. See http://msdn.microsoft.com/en-us/library/aa171356(office.11).aspx for reference.
The following code example lists the visible toolbars and controls on the Standard toolbar. When it finds a control labeled Open, it calls the control. This should display the "File β Open" dialog:
#!/usr/bin/perl use strict; use warnings; use Win32::OLE qw(in with); $Win32::OLE::Warn = 3; my $app = get_excel(); $app->{Visible} = 1; my $book = $app->Workbooks->Add; for my $bar (in $app->CommandBars) { if ( $bar->{Visible} ) { print $bar->{Name}, "\n"; } } print "Controls in the 'Standard' toolbar:\n"; my $bar = $app->CommandBars->{Standard}; for my $control (in $bar->{Controls}) { print "\t", $control->{Caption}, "\n"; if ( $control->{Caption} =~ /^Open/ ) { print "opening ...\n"; $control->Execute; } } sub get_excel { my $excel; eval { $excel = Win32::OLE->GetActiveObject('Excel.Application'); }; die " $@ \n" if $@ ; unless(defined $excel) { $excel = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit }) or die "Oops, cannot start Excel: ", Win32::OLE->LastError, "\n"; } return $excel; } __END__
NTN
source share