Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My perl file is following:
#33.pl use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; # imports word constants like wdFormtaDosTxtLineBreaks my $Word = Win32::OLE->new( 'Word.Application', 'Quit' ); $Word->{'Visible'} = 1; # second argument tells OLE what to do if everything goes tits up my $Document = $Word->Documents->Open( "f:\\aa.doc" ); $Document->SaveAs( { FileName => 'bb.htm', FileFormat => wdFormatHTML +} ); # NOTE!!! wdFormatDOSTextLineBreaks, wdFormatHTML, etc., are constants +, not strings, so don't quote them! $Document->Close(); $Word->Quit(); exit( 0 ); ##############
error essage:
Bareword "wdFormatHTML" not allowed while "strict subs" in use at +33.pl lines 18
Why? when I didn't use "use strict", no html file putout .

can you help me ? thanks.

update (broquaint): added formatting

Replies are listed 'Best First'.
Re: Can I save my document to html page?
by Courage (Parson) on Jan 21, 2003 at 13:43 UTC
    your constant wdFormatHTML is in trouble here.

    Actually you should do something like

    my $constref = Win32::OLE::Const->Load($Word); # and then... $Document->SaveAs( { FileName => 'bb.htm', FileFormat => $constref->{wdFormatHTML}} );

    Courage, the Cowardly Dog

Re: Can I save my document to html page?
by elbow (Scribe) on Jan 21, 2003 at 10:38 UTC
    Just to make it easy on the eyes:
    use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; # imports word constants like wdFormtaDosTxtLineBreaks my $Word = Win32::OLE->new( 'Word.Application', 'Quit' ); $Word->{'Visible'} = 1; # second argument tells OLE what to do if everything goes tits up my $Document = $Word->Documents->Open( "f:\\aa.doc" ); $Document->SaveAs( { FileName => 'bb.htm', FileFormat => wdFormatHTML +} ); # NOTE!!! wdFormatDOSTextLineBreaks, wdFormatHTML, etc., are #constants, not strings, so don't quote them! $Document->Close(); $Word->Quit(); exit( 0 );


    elbow

    update nevermind - broquaint did it too.....
      Looking at the error message, it seems to me that the constant wdFormatHTML is not defined, hence the complaint about the bareword. I'm not a Win32 programmer, but maybe there's a spelling error somewhere or something like that.

      Arjen

      Updated:forgot a word.

        You could try something like this to list all the wd* constants which are imported (untested):

        C:\perl -M'Win32::OLE::Const "Microsoft Word"'\ -e 'print join("\n", grep { /^wd/ } keys %main::;

        Arjen

Re: Record a macro to steer OLE Apps
by Brutha (Friar) on Jan 21, 2003 at 16:13 UTC
    Get some help from Microsoft and use an old trick. Record a macro with all necessary clicks and key-presses and translate that to perl. In your case:

    - open word and a new document
    - type some blabla...
    - start recording a macro
    - save as HTML (enter all necessary stuff)
    - stop recording and edit the macro

    that results in the following:

    ActiveDocument.SaveAs FileName:="Test1.htm", FileFormat:=102, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
    There are your parameters, drop the ones you do not need. Record it yourself, because I used a german version of word97.

    ---
    And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
    (Terry Pratchett, Small Gods)

Re: Can I save my document to html page?
by castaway (Parson) on Jan 21, 2003 at 11:49 UTC
    Hmm, 'wdFormatHTML' is a constant in the enum 'WdSaveFormat', maybe you can do something like:
    $Word->{'wdFormatHTML'} or
    $Word->{'WdSaveFormat'}->{'wdFormatHTML'}

    Failing all that, the value of 'wdFormatHTML' is 8 ;)

    C.
    *UNTESTED*

      actually value of wdFormatText differs between Word97 and Word2000.

      That said, you will in trouble when using such constants everywhere!