Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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.

Replies are listed 'Best First'.
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.
      Selection.InlineShapes.AddOLEControl ClassType:="Forms.CheckBox.1
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.


    Flex the Geek

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://259348]
Approved by Enlil
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2017-01-23 07:03 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (191 votes). Check out past polls.