Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Do you know where your variables are?
 
PerlMonks  

create checkbox in word document

by pcxpuser (Initiate)
on May 20, 2003 at 03:06 UTC ( #259348=perlquestion: print w/ replies, xml ) Need Help??
pcxpuser has asked for the wisdom of the Perl Monks concerning the following question:

I've been using win::32 ole to create word documents and have been able to create and manipulate documents successfully. I am now wondering how to add/change form fields in the documents such as a checkbox.

Comment on create checkbox in word document
Re: create checkbox in word document
by Zero_Flop (Pilgrim) on May 20, 2003 at 03:47 UTC
    As I have mentioned in the past the Macro function is your friend.
    vb code
    Selection.InlineShapes.AddOLEControl ClassType:="Forms.CheckBox.1"

    Just convert this to perl. It may take a little trial and error, but you should be able to do it fairly quickly.
      Zero_Flop is right about the macros. If, however, you can't convert it you can always (as a possible last resort) create the macro in Word and then run it with a Perl command.
      • Create and name the macro in word
      • Declare it at the top of your code
        package MACRO-NAME;
      • When you need the action from the macro, you call it in perl like this:
        $Word->Documents->Open("$dir\\$file") or die "Can't open ", Win32::OLE +->LastError()); $Word->Run("MACRO-NAME");
      This has saved me some time on some hurry-up projects where I didn't have success converting the VBA directly to Perl.
Re: create checkbox in word document
by cacharbe (Curate) on May 20, 2003 at 13:16 UTC
    To answer your question with perl:
    use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 2; my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit'); $Word->{'Visible'} = 1; my $Doc = $Word->Documents->Add(); $Word->Selection->WholeStory; $Word->Selection->InlineShapes->AddOLEControl({ClassType=>'Forms.Ch +eckBox.1'});

    You'll probably have to read the class documentation to get the names for the ClassTypes for OLEControls, but that's a good exercise for the reader.

    C-.

    ---
    Flex the Geek

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://259348]
Approved by Enlil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-04-18 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls