Here is my code to implement:Sub Macro1() ' ' Macro1 Macro ' ' Range("B1:Q1").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge End Sub
The merge works correctly! Alas, the center does not:use Win32::OLE qw(in with CP_UTF8); Win32::OLE->Option(CP => CP_UTF8); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; $Win32::OLE::Warn = 3; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32: +:OLE->new('Excel.Application', 'Quit'); # get already active Excel $Excel->{'Visible'} = 1; my $Book = $Excel->Workbooks->Open('foo.xlsx'); my $Sheet = $Book->Worksheets(1); $Sheet->Range("B1:Q1")->Merge(); $Sheet->Range("B1:Q1")->{HorizontalAlignment} = 'xlCenter';
Does anyone know how to fix it?Win32::OLE operating in debugging mode: _Unique => 1 OLE exception from "Microsoft Excel": Unable to set the HorizontalAlignment property of the Range class Win32::OLE(0.1709) error 0x80020009: "Exception occurred" in PROPERTYPUT "HorizontalAlignment" at C:\Users\boss\Dropbox C:\t +mp\merge-center.pl line 11.
In reply to Win32::OLE Excell Merge & Center by cormanaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |