in reply to TK and Word do not work together

when you restart the program and press the second button, the program get stuck.

I don't use Windows so I can't run Win32::OLE; but what exactly does it do when it gets stuck? Are there error messages? What exactly happens?

The Tk code seems to work ok, so the problem seems to be in the sub oleTest{}.

My advice would be to try and run the oleTest sub as a standalone program, and see what the error is in that code. There is some working OLE code in Win32::OLE: How to get the page number from ms-word?


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: TK and Word do not work together
by priyaviswam (Sexton) on Nov 15, 2011 at 11:24 UTC

    Actually you have make that object visible. Please find below the code :

    #!/usr/bin/perl -w use Tk; use Win32::OLE; use Win32::OLE::Const; my $mw = MainWindow->new; $mw->Button(-text => "Run (Closed Widget)", -command => sub { $mw->destroy() })->pack; $mw->Button(-text => "Run (Opened Widget)", -command => sub { oleTest() })->pack; MainLoop; oleTest(); sub oleTest { my $word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add(); print "Before OLE\n"; $document->InlineShapes->AddOLEObject("EMBED",'C:\tmp\test.dat'); +# this can be ANY test.dat print "After OLE\n"; $document->SaveAs('c:\tmp\test.docx'); $document->activewindow->{'Visible'}="True"; }

      Thanks for the code. But even with your modification the program does stuck when I press the second Button
Re^2: TK and Word do not work together
by Bauldric (Novice) on Nov 16, 2011 at 14:53 UTC
    Thanks for your answer. But if you press the first Button, the oleTest runs well. If th oleTest sub runs as a standaloe program there occurs no error
      But if you press the first Button, the oleTest runs well.

      Sure, the way you have MainLoop; before oleTest(), the first button destroys the Tk event loop, leaving OLE to run unfettered.

      Apparently the Tk eventloop and the way OLE runs, are not compatible, but I can't test that here. Usually, you would put your oleTest() into a separate thread, if it interferes with Tk's eventloop.


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh