Win32::OLE on MS Word using Selection.Find.Execute

2010-09-14 Thread Kevin Gibbs
Hi Peter,

This is a translation of a script from technet that works:

use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

#
http://www.microsoft.com/technet/scriptcenter/resources/officetips/may05
/tips0512.mspx
   
  my $word = new Win32::OLE 'Word.Application','' or die Cannot start
word!\n;
 
  $word-{visible}=1;
  
  my ( $file, $text ) = @ARGV;
   
  my $doc = $word-Documents-Open( $file );

  $selection = $word-Selection;

  $selection-Find-{Text} = $text;

  $selection-Find-{Forward} = TRUE;
  
  $selection-Find-{MatchWholeWord} = TRUE;

  if ( $selection-Find-Execute ) {
print The search text was found\n;
  } else {   
print The search text was not found\n;
  }

Cheers,

Kev.

-Original Message-
Date: Sun, 12 Sep 2010 16:43:24 -0400
From: Peter Buck pb...@his.com
Subject: Win32::OLE on MS Word using Selection.Find.Execute
To: perl-win32-users@listserv.ActiveState.com
Message-ID: 4c8d3b6c.8010...@his.com
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

  Does anyone have an example of a perl script acting on MS Word
documents using Win32::OLE and Selection.Find.Execute?  I have read the
Win32 man page but its examples for Excel and Access don't help.  I 
found a Powershell script that does what I want but can't translate.   
The parts I'm confused on are (1) setting the parameters used in the
Selection.Find.Execute() invocation (particularly the boolean values,
since perl doesn't do booleans) and the actual invocation of
Selection.Find.Execute().

I did find an example using $search- Execute() but this doesn't appear
to allow setting all the parameters that Selection.Find.Execute() does.

Also, it operates on $doc- Content-Find while Selection.Find.Execute()
operates on $doc-Selection (if I'm right).  And I'm using Homekey(6) to
take me to the top of the document, which is linked to Selection and
doesn't seem to work in my $doc-Content-Find attempts.

Any help or direction to documentation much appreciated.

Thanks - Toolsmith

# ExpandAcronyms.ps1
# read acronym list, expand acronyms in target MS Word document #
syntax: ExpandAcronyms wordDocument

function make-change {
 $FindText = $args[0]
 $FullText = $args[1]
 $ReplaceText = $FullText ($FindText)

 $ReplaceAll = 1
 $FindContinue = 1
 $MatchCase = $True
 $MatchWholeWord = $True
 $MatchWildcards = $False
 $MatchSoundsLike = $False
 $MatchAllWordForms = $False
 $Forward = $True
 $Wrap = $FindContinue# don't want it wrapping, wish I knew 
what this meant
 $Format = $False

 $objWord.Selection.HomeKey(6)  Null
 $result = $objSelection.Find.Execute($FindText,$MatchCase,
 $MatchWholeWord,$MatchWildcards,$MatchSoundsLike,
 $MatchAllWordForms,$Forward,$Wrap,$Format,
 $ReplaceText,$ReplaceAll)
  if ( $result -eq $true ) {
  $Findtext|$FullText
 }

}

if ( $args.count -lt 1 ) {
 cd $env:temp
 $strWordFile = [string](resolve-path(Read-Host Enter Path of Word
file to be processed)) } else {
 $strWordFile = [string](resolve-path($args[0])) }


$objWord = New-Object -ComObject word.application
$objWord.Visible = $True
$objDoc = $objWord.Documents.Open($strWordFile)

$objSelection = $objWord.Selection

$d = get-content d:/temp/acronyms.txt# read file of acronym | 
definition
foreach ( $l in $d ) {
 ($acro, $def) = $l.split('|')# build array 
of acronym, definition
 make-change $acro $def
}
Finished
$objWord.Selection.HomeKey(6)  Null
This e-mail (including any attachments) may be confidential and may contain 
legally privileged information. You should not disclose its contents to any 
other person. If you are not the intended recipient, please notify the sender 
immediately.

Whilst the Council has taken every reasonable precaution to minimise the risk 
of computer software viruses, it cannot accept liability for any damage which 
you may sustain as a result of such viruses. You should carry out your own 
virus checks before opening the e-mail(and/or any attachments).

Unless expressly stated otherwise, the contents of this e-mail represent only 
the views of the sender and does not impose any legal obligation upon the 
Council or commit the Council to any course of action.
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Output to select windows??

2005-01-19 Thread Kevin Gibbs
Here's a TK example.  Guess you're not expecting the user to interact with
your Windows, they are just to display results in.

Each window appears as a separate icon on the start bar.  I've never been
able to work out how to stop this happening.  A simple solution would be
rather than have 3 windows, have 1 window with three different text areas to
display results in.  That might even be a better idea thinking about it.

Kev.

use Tk;
use Tk::ROText;

  my $win = MainWindow-new(); 
   
  $win-bind('Alt-Key-F4' = sub { exit } );
  $win-title(Window);
  $win-withdraw;  # hide mainwindow
   
  my @childwins;   # array to store child
windows and their widgets
  my $x = 10;
   
  # create child windows which will display the results
   
  for (my $i = 0; $i  3 ; $i++ ) {

$childwins[$i][0] = $win-Toplevel();
$childwins[$i][0]-title( Window $i );
$childwins[$i][0]-geometry( +$x+10, );  # set position of subwindows
$x += 250; # move x pos of next window
 
$childwins[$i][1] = $childwins[$i][0]-Scrolled( 'ROText', 
  -scrollbars  = 'oe',
  -height  = 20,
  -width   = 30,
  -background  = 'white',
)-grid( -row = 1 , -columnspan = 5 , -pady = 2,
-sticky ='nsew');
$childwins[$i][0]-Display; 
  }

  #
  # Do something and display results in windows
  #

  for (my $j = 0; $j  100 ; $j++ ) {
for ( my $i = 0; $i  3; $i++ ) {
  $childwins[$i][1]-insert( end, Window $i, Line $j\n );  # insert
text on window
  $childwins[$i][1]-see( end ); # make
sure will be visible
  
  $childwins[$i][0]-update;   # make
our updates visible 
}
sleep 1;
  }

-Original Message-
From: Glenn Linderman [mailto:[EMAIL PROTECTED] 
Sent: 18 January 2005 19:12
To: Charles Maier
Cc: Kevin Gibbs; perl-win32-users@listserv.ActiveState.com
Subject: Re: Output to select windows??


On approximately 1/18/2005 10:39 AM, came the following characters from 
the keyboard of Charles Maier:
 I looked at Win32:Console. One of the first things it talks about 
 is that ONLY ONE window may be open for a process and how to detach an 
 open console and re-open a console. This is not true??

Sorry, maybe I should have read the documentation again.  I had gotten 
the impression that a program can have multiple console windows from 
something I read somewhere, but perhaps that is not possible via 
Win32::Console, only at the Windows API level.

 Would someone please offer a simple example of perl working with 
 multiple windoz windows??

Well, the sample code attached is from Win32::GUI's (version 1.0) sample 
programs.  It shows multiple child windows within a parent window (If 
you File/New several times).  But really, you likely only need a single 
window, with multiple text boxes, for each type of output you want.

Or, since the data you mention talks about lists of things, maybe list 
boxes would suffice, or even be preferable.

This e-mail is confidential and may contain legally privileged information.  
You should not disclose its contents to any other person.  If you are not the 
intended recipient, please notify the sender immediately.

Whilst the Council has taken every reasonable precaution to minimise the risk 
of computer software viruses, it cannot accept liability for any damage which 
you may sustain as a result of such viruses.  You should carry out your own 
virus checks before opening the e-mail (and/or any attachments).

Unless expressly stated otherwise, the contents of this e-mail represent only 
the views of the sender and do not impose any legal obligation upon the Council 
or commit the Council to any course of action.



This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Output to select windows??

2005-01-18 Thread Kevin Gibbs
Chuck,

Yes but you'll need to be clearer on what you want.

If you're looking for create GUI interface then there
is TK, Win32::GUI or WX.

If you want to send characters to a multiple console
windows then there is Win32::Setupsup.

Kevin.

--

Date: Sun, 16 Jan 2005 17:54:32 -0500
From: Charles Maier [EMAIL PROTECTED]
Subject: Output to select windows??
To: Perl-Win32-Users Mailing List
perl-win32-users@listserv.activestate.com
Message-ID: [EMAIL PROTECTED]
Content-Type: text/plain;   charset=iso-8859-1


Can perl open multiple windows... and selectively send text to these
windows??

TIA
Chuck

This e-mail is confidential and may contain legally privileged information.  
You should not disclose its contents to any other person.  If you are not the 
intended recipient, please notify the sender immediately.

Whilst the Council has taken every reasonable precaution to minimise the risk 
of computer software viruses, it cannot accept liability for any damage which 
you may sustain as a result of such viruses.  You should carry out your own 
virus checks before opening the e-mail (and/or any attachments).

Unless expressly stated otherwise, the contents of this e-mail represent only 
the views of the sender and do not impose any legal obligation upon the Council 
or commit the Council to any course of action.



This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Screen Saver settings

2004-09-03 Thread Kevin Gibbs
Hi John,

The screen saver settings are stored in the registry.
The following should tell you what the settings are:

  use Win32::TieRegistry (TiedRef = \$reg) ;
  use Win32;

  my $control = $reg-{CUser\\Control Panel};
  my $desktop = $control-{Desktop};

  print ScreenSaver:  . scalar ($desktop-{SCRNSAVE.EXE}).\n;
  print Active:  .scalar ($desktop-{ScreenSaveActive}).\n;
  print Secure:  . int( Win32::IsWin95() ?
$desktop-{ScreenSaveUsePassword} : $desktop-{ScreenSaverIsSecure} ).\n;
  print Timeout:  . scalar ($desktop-{ScreenSaveTimeOut}).\n;

Hope that helps.

Kev.

--
Date: Wed, 1 Sep 2004 17:41:04 -0500
From: Herbold, John W. [EMAIL PROTECTED]
Subject: Screen Saver settings
To: '[EMAIL PROTECTED] '
[EMAIL PROTECTED],'Steven
Manross
' [EMAIL PROTECTED],
'[EMAIL PROTECTED]
'  [EMAIL PROTECTED]
Message-ID:
[EMAIL PROTECTED]
Content-Type: text/plain; charset=iso-8859-1

Any body know of a way to use Perl to see if a workstation has password
protection enabled and what the timeout is for the workstations screensaver?

Code snippets would be perfect, ideas and suggestions would be most helpful.

Thanks !

John W. Herbold Jr.
Security Specialist

This e-mail is confidential and may contain legally privileged information.  You 
should not disclose its contents to any other person.  If you are not the intended 
recipient, please notify the sender immediately.

Whilst the Council has taken every reasonable precaution to minimise the risk of 
computer software viruses, it cannot accept liability for any damage which you may 
sustain as a result of such viruses.  You should carry out your own virus checks 
before opening the e-mail (and/or any attachments).

Unless expressly stated otherwise, the contents of this e-mail represent only the 
views of the sender and do not impose any legal obligation upon the Council or commit 
the Council to any course of action.



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Determining Available Disk Space

2004-08-26 Thread Kevin Gibbs
Just for the record, there is also Win32::DriveInfo::DriveSpace().

Kev.

--

Message: 14
Date: Wed, 25 Aug 2004 12:34:03 -0500
From: Dirk Bremer \(NISC\) [EMAIL PROTECTED]
Subject: Re: Determining Available Disk Space
To: [EMAIL PROTECTED]
Message-ID: [EMAIL PROTECTED]
Content-Type: text/plain;   charset=iso-8859-1

Thanks to all who responded. I ended up with this to produce my desired
result:

# Construct a WMI object instance.
my $WMI = Win32::OLE-GetObject(winmgmts:mailcd\\root\\cimv2);

# Query for the D-drive information.
my $Collection = $WMI-ExecQuery(SELECT * FROM Win32_LogicalDisk where
DeviceID = 'D:');

# Calculate the free-space in megabytes.
my $Space;
foreach my $Obj (in $Collection) {$Space = int($Obj-{FreeSpace})}

Note the adjustment that I made to the SELECT statement to query only the
single specific drive. I will use the raw free space number to compare
against the raw size of the current file that will be copied to determine if
there is enough free disk space to perform the copy operation.

As an aside, is there a way to directly access the returned hash elements
rather than using the following loop?

foreach my $Obj (in $Collection) {$Space = int($Obj-{FreeSpace})}


Dirk Bremer - Systems Programmer II - ESS/AMS  - NISC St. Peters
USA Central Time Zone
636-922-9158 ext. 8652 fax 636-447-4471

[EMAIL PROTECTED]
www.nisc.cc

This e-mail is confidential and may contain legally privileged information.  You 
should not disclose its contents to any other person.  If you are not the intended 
recipient, please notify the sender immediately.

Whilst the Council has taken every reasonable precaution to minimise the risk of 
computer software viruses, it cannot accept liability for any damage which you may 
sustain as a result of such viruses.  You should carry out your own virus checks 
before opening the e-mail (and/or any attachments).

Unless expressly stated otherwise, the contents of this e-mail represent only the 
views of the sender and do not impose any legal obligation upon the Council or commit 
the Council to any course of action.



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Perl-Win32-Users digest, Vol 1 #1729 - 17 msgs

2003-12-30 Thread Kevin Gibbs
Bill,

Just out of interest I tried a variation on your script with 3 buttons to
open up the html file.  One button used System, one used the windows
shell (via OLE) and one used OLE to control IE directly.

On my machine (w2k), Shell takes the longest, system is slightly quicker,
and OLE is pretty much instantaneous.  Doesn't answer your question but
gives an alternative but only if you use IE.

Code is below (cut and pasted your code so I'm using your original style).

use strict ;
use Tk ;
use Win32::OLE;

 my $file = 'c:\\temp\\contents list.html';
 system ( $file ) ;

 my  $mw = MainWindow
 - new ( -title = 'Test Window' ) ;

 my  $b = $mw
- Button
 ( -text  = Shell
 , -borderwidth = '1'
 , -padx = '4'
 , -relief = 'raised'
 , -command = \shellpress
 )
- pack() ;


 $mw- Button
 ( -text  = System
 , -borderwidth = '1'
 , -padx = '4'
 , -relief = 'raised'
 , -command = \systempress
 )
- pack() ;

 $mw- Button
 ( -text  = OLE
 , -borderwidth = '1'
 , -padx = '4'
 , -relief = 'raised'
 , -command = \olepress
 )
- pack() ;

 MainLoop ;

sub shellpress {

   my $shell = Win32::OLE-new( Shell.Application );
   my $open = $shell-Open( $file );
}

sub systempress {
   my  $r = system ( $file ) ;
}

sub olepress {
  my $ie = Win32::OLE-new('InternetExplorer.Application');
  $ie-{Visible} = 1;
  $ie-Navigate( $file );
}

Kev.

-Original Message-
From: Conrad, Bill (ThomasTech)  
To: [EMAIL PROTECTED]
Subject: RE: PERL TK Question
Date: Mon, 29 Dec 2003 10:38:06 -0500

Hi All

This analysis of my programming style is this first I have heard. My
style was developed as a result of teaching structured programming. I found
students learned the concepts of Objects and Relationships by placing these
on separate lines with indenting to show what was contained in what. By
lining the commas up with the parenthesis on the left it was more obvious
what the structure was. It was easier for the Student to identify what I was
discussing and to add their own comments to each line. It was just my way of
doing things. I don't criticize anyone else for their way of doing things.
To each his own. But I do find it more difficult to understand a Script that
has everything written on one line. When I write code, Every Line is
Documented to give the next person a better chance to understand what I have
done. I find that very lacking in much of what I see today.

But the style of my coding wasn't the object of my question. I just
find it hard to believe that it was such an issue and my original question
wasn't given much thought. 

Sorry to those I may have offended.

Bill Conrad

This e-mail is confidential and may contain legally privileged information.  You 
should not disclose its contents to any other person.  If you are not the intended 
recipient, please notify the sender immediately.

Whilst the Council has taken every reasonable precaution to minimise the risk of 
computer software viruses, it cannot accept liability for any damage which you may 
sustain as a result of such viruses.  You should carry out your own virus checks 
before opening the e-mail (and/or any attachments).

Unless expressly stated otherwise, the contents of this e-mail represent only the 
views of the sender and do not impose any legal obligation upon the Council or commit 
the Council to any course of action.



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Win32::SetupSup and ActiveState Perl 8

2003-12-16 Thread Kevin Gibbs
Does anyone know of a ppm for SetupSup that works with the latest version of
Perl?

Thanks,

Kevin.

This e-mail is confidential and may contain legally privileged information.  You 
should not disclose its contents to any other person.  If you are not the intended 
recipient, please notify the sender immediately.

Whilst the Council has taken every reasonable precaution to minimise the risk of 
computer software viruses, it cannot accept liability for any damage which you may 
sustain as a result of such viruses.  You should carry out your own virus checks 
before opening the e-mail (and/or any attachments).

Unless expressly stated otherwise, the contents of this e-mail represent only the 
views of the sender and do not impose any legal obligation upon the Council or commit 
the Council to any course of action.



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs