in reply to Win32::OLE Examples?

Definitions: Sure, I have plenty of OLE examples, what were you hoping to see?

Word

use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit'); $Word->{'Visible'} = 1; $Word->Documents->Add || die("Unable to create document ", Win32::OLE- +>LastError()); my $MyRange = $Word->ActiveDocument->Content; my $mytxt = "Some Random Text"; # I'll fill this in later # add a table that is the header portion, 1 column by 1 row $Word->ActiveDocument->Tables->Add({ Range => $MyRange, NumRows => 1, NumColumns => 1, }); $Word->Selection->TypeText ({ Text => $mytxt}); $Word->Selection->MoveRight({Count => 1}); $Word->Selection->TypeText ({ Text => "A little more text"});

PowerPoint

use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft PowerPoint'; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $PptApp = Win32::OLE->GetActiveObject('PowerPoint.Application')|| +Win32::OLE->new('PowerPoint.Application', 'Quit'); $PptApp->{Visible} = 1; my $Presentation = $PptApp->Presentations->Add(); #my $Presentation = $PptApp->Presentations->Open({FileName=>'<SOMEFILE +NAME>',ReadOnly=>1}); my $Slide = $Presentation->Slides->Add({Index=>1 , Layout=>ppLayoutTex +t}); $Slide->{Name} = "Slide1"; my $TextBox=$Slide->Shapes->AddTextbox({Orientation=>1, Left=>5, Top=>5, Width=>250, Height=>250,}); $TextBox->TextFrame->TextRange->{Text} ="Big Ole Test"; my $Title=$Slide->Shapes->{Title}; $Title->TextFrame->TextRange->{Text} ="Title Test"; my $NewSlide = $Slide->Duplicate(); $NewSlide->{Name} = "Slide2";

OutLook

use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Outlook'; $|++; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $OL = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application', 'Quit'); my $NameSpace = $OL->GetNameSpace("MAPI"); my $Folder = $NameSpace->GetDefaultFolder(olFolderInbox); # map {print "Attachment Name: ". $_->Attachment(1)->{Name} ."\n";} +(in ($Folder->{Items})); foreach my $msg (in $Folder->{Items}){ foreach my $atch (in $msg->{Attachments}){ my $filename = "C:\\atchs\\" . $atch->{FileName}; #print $atch->{FileName} ." in message ". $msg->{Subject} . +"\n"; print $filename ."\n";#." in message ". $msg->{Subject} ."\ +n"; $atch->SaveAsFile($filename); } }
I mean, really, what are you hoping to accomplish? Did you have a task in mind?

You'll need to use an object browser, something like Active States html based one, or MS various tools.

C-.

Update: Added defn links

Replies are listed 'Best First'.
Re: Re: Win32::OLE Examples?
by Flame (Deacon) on Mar 20, 2002 at 22:13 UTC
    Ok, I take it only microsoft products work with OLE?

    Do you have an example with WordPad or something free like that?

    Thanks



    "Weird things happen, get used to it."

    Flame ~ Lead Programmer: GMS

      The point is, OLE is a Microsoft "technology", so it's really the other way around. OLE only works on Micrsoft and Microsoft compliant software products. Technically, it works with certain applications and codebases that implement an interface named IDispatch.

      Unfortunately, from what I can see, Wordpad really has no interfaces derived from IDispatch, which means no OLE (someone please correct me if I'm wrong).

      I ask again, though, what are you thinking of doing? Perhaps there is another way around it that a few here could suggest.

      C-.

        I'm using Win32::GUI and I have a rich-text box. I was attempting to use it as a WYSIWYG html editor (of sorts). I actually was able to make it work, up to a point, but I've been looking for alternatives. One of the people on the Win32::GUI mailing list suggested I take a look at Win32::OLE.

        At the moment, I have no specific goal, but since my interest was piqued, I want to see if I can actually get my hands on a working example.

        Could you simply describe what a program using OLE might look like? What purposes could one fulfill?

        By automation, I assume that means that it actually launches the other program and manipulates it? Or does it just run portions of the other program. For example, could OLE be used to create a browser with IE and Win32::GUI? Or would it just be limited to opening IE and controling it?

        Thanks, I hope this explains what I'm trying to figure out a little better.



        "Weird things happen, get used to it."

        Flame ~ Lead Programmer: GMS

Re^2: Win32::OLE Examples?
by ewittry (Initiate) on Jan 10, 2008 at 22:16 UTC
    Any one know how to link some text to a different slide?