Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Win32::OLE Word Macro Conversion

by offspinner (Initiate)
on Nov 24, 2004 at 12:36 UTC ( [id://410123]=perlquestion: print w/replies, xml ) Need Help??

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

Hi there all, I'm writing a simple script to batch convert word documents into HTML. However, I need also to disable the impossibly stupid "Smart Tags" that get embedded. The VBA macro below contains the important lines ( .EmbedSmartTags = False, .LabelSmartTags = False). Could anyone give me a clue to getting that functionality into the script at the bottom? Very many thanks! Richard

########### MACRO
Sub yadda() ' ' yaddaMacro ' Macro recorded 23/11/2004 by Richard Barrett-Small ' With Options .LocalNetworkFile = False .AllowFastSave = True .BackgroundSave = True .CreateBackup = False .SavePropertiesPrompt = False .SaveInterval = 10 .SaveNormalPrompt = False .DisableFeaturesbyDefault = False End With With ActiveDocument .ReadOnlyRecommended = False .EmbedTrueTypeFonts = False .SaveFormsData = False .SaveSubsetFonts = False .DoNotEmbedSystemFonts = True .Password = "" .WritePassword = "" .DisableFeatures = False .EmbedSmartTags = False .SmartTagsAsXMLProps = False .EmbedLinguisticData = True End With Application.DefaultSaveFormat = "" With autocorrect .CorrectInitialCaps = True .CorrectSentenceCaps = True .CorrectDays = True .CorrectCapsLock = True .ReplaceText = True .ReplaceTextFromSpellingChecker = True .CorrectKeyboardSetting = False .DisplayAutoCorrectOptions = True .CorrectTableCells = True End With With Options .LabelSmartTags = False .DisplaySmartTagButtons = True End With End Sub
#!C:\Perl\bin\perl5.8.4.exe use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; system("set PERL5OPT=-MWild"); my $file = $ARGV[0] or die "Perl says: $!\n\nThis means:\nSyntax is...\n\ filename(s)\n"; my $Word = Win32::OLE->new('Word.Application', 'Quit'); while ( $file = shift) { print "$file.html\n"; # $Word->{'Visible'} = 1; # if you want to see what's going on $Word->Documents->Open("$file") || die("Unable to open document $file\ +n", Win32::OLE->LastError()); $Word->ActiveDocument->SaveAs ( { FileName => "$file.html", FileFormat => FormatHTML } ); }

Replies are listed 'Best First'.
Re: Win32::OLE Word Macro Conversion
by maa (Pilgrim) on Nov 24, 2004 at 13:11 UTC

    You have

    With Options .LocalNetworkFile = False

    Now... Options is unqualified which means it belongs to the Application object (VBA assumes this), perl won't... try:

    $Word->Options->{LocalNetworkFile}=0; ... $Word->Options->{LabelSmartTags}=0;
    (untested!)... HTH - Mark
      That's cracked it! Thank you!

      Right. And to "emulate" the with object statement you could do something like this:

      for ($Word->Options) { $_->{LocalNetworkFile}=0; $_->{LabelSmartTags}=0; }
      { my %opt = ( LocalNetworkFile => 0, AllowFastSave => 1, BackgroundSave => 1, CreateBackup => 0, SavePropertiesPrompt => 0, SaveInterval => 10, SaveNormalPrompt => 0, DisableFeaturesbyDefault => 0, ); map $Word->Options->{$_} => $opt{$_}, keys %opt; }

      We'd like to help you learn to help yourself
      Look around you, all you see are sympathetic eyes
      Stroll around the grounds until you feel at home
         -- P. Simon in Mrs. Robinson

        That's Just Dandy. Thanks again!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://410123]
Approved by BrowserUk
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-06-20 19:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.