Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Excel VB Controls

by Unanimous Monk (Sexton)
on May 03, 2006 at 03:39 UTC ( [id://547049]=note: print w/replies, xml ) Need Help??


in reply to Excel VB Controls

You'll want to check out the "Shapes" method in the Worksheet object using Marto's Where do I find documentation for the object models? reference.

Each form control is a "Shape", and its values can be manipulated through the OLEFormat object.

The following sample code should put you on the right track. It will create a worksheet with a check box, check it, and then uncheck it. (If you're using something other than Excel 2003, you'll need to update the "Microsoft Excel 11.0 Object Library" to the correct version)

use strict; use Win32::OLE; use Win32::OLE::Const("Microsoft Excel 11.0 Object Library"); # Load Excel objects my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; my $book = $xl->Workbooks->Add; my $sheet = $book->Worksheets->Add; # Add a check box to manipulate $sheet->Shapes->AddFormControl(xlCheckBox, 0, 0, 250, 250); # Get the name of our checkbox my $chkBoxName = $sheet->Shapes(1)->Name; # Check the check box $sheet->Shapes($chkBoxName)->OLEFormat->Object->{Value} = 1; sleep 2; # Uncheck the check box $sheet->Shapes($chkBoxName)->OLEFormat->Object->{Value} = 0;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://547049]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found