- 论坛徽章:
- 0
|
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "hello"
.Replacement.Text = "hi"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
++++++++++++++++++++++++++++++++++++++++++
以上是word里面录制的宏命令:将word文档中的“hello”替换成"hi"。
以下是利用Win32::OLE模块转化成的perl脚本。但是运行之后没有达到预定的目的,也没有任何错误提示。请问谁有这方面的经验,麻烦给出一些提示。多谢!
++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/perl
use strict;
use warnings;
use constant True => 1;
use constant False => 0;
print "Hello, World...\n";
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';
my $file = 'E:\test.docx';
my $word = Win32::OLE->new('Word.Application', 'Quit');
$word->{'Visible'} = 1;
my $doc = $word->Documents->Open ($file) or die ("Unable to open document", Win32::OLE->LastError ());
my $Selection = $word->Selection();
$Selection->Find->{Text} = 'Hello';
$Selection->Find->{Replacement} = 'hi';
$Selection->Find->{Forward} = 1;
$Selection->Find->{Wrap} = wdFindContinue;
$Selection->Find->{Format} = 0;
$Selection->Find->{MatchCase} = 0;
$Selection->Find->{MatchWholeWord} = 0;
$Selection->Find->{MatchByte} = 1;
$Selection->Find->{MatchWildcards} = 0;
$Selection->Find->{MatchSoundsLike} = 0;
$Selection->Find->{MatchAllWordForms} = 0;
$word->ActiveDocument->Close ;
$word->Quit;
+++++++++++++++++++++++++++++++++++++++++++ |
|