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
####
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';
####
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:\tmp\merge-center.pl line 11.