Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Win::OLE Excel: disable macros

by haukex (Archbishop)
on Feb 16, 2022 at 10:07 UTC ( [id://11141415]=note: print w/replies, xml ) Need Help??


in reply to Win::OLE Excel: disable macros

The documentation of Workbooks.Open says:

By default, macros are enabled when opening files programmatically. Use the AutomationSecurity property to set the macro security mode used when opening files programmatically.

This works for me:

use warnings; use strict; use Win32::OLE (); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors my $Excel = Win32::OLE->new('Excel.Application', 'Quit') or die "Faile +d to open Excel"; # or to get running Excel instance: Win32::OLE->GetActiveObject('Excel +.Application') my $const = Win32::OLE::Const->Load('Microsoft Office '.$Excel->{Versi +on}.' Object Library'); $Excel->{AutomationSecurity} = $const->{msoAutomationSecurityForceDisa +ble}; $Excel->{Visible} = 1; my $Book = $Excel->Workbooks->Open("filename.xlsm"); $Book->Activate; # ... $Excel->Quit;

Replies are listed 'Best First'.
Re^2: Win::OLE Excel: disable macros
by Ratazong (Monsignor) on Feb 16, 2022 at 12:25 UTC

    Thank you haukex and Anonymous Monk!

    msoAutomationSecurityForceDisable does the trick :-) .

    note: I found out that it works with $Excel->Workbooks->Open, but it didn't work with $Excel->Workbooks->OpenXML

    Rata

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11141415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2024-03-28 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found