Thanks
@teadrinker, you got it. COM can be touchy; I thought it would need the "xlA1", but I guess this is the default, so isn't needed?
Some background:
I've been going through
@Joe Glines' posts, and there was one that talks about setting the horizontal and vertical alignment. The only issue I had was that you always had to define the range first, when I would rather have it so I can select a cell(s), and it will apply it to whatever is selected. The code is as per below:
Code: Select all
;-------------------------------------------------------------
Pause & z::
XL_Handle(XL_App,1) ;Connect to the active instance of Excel.
;These work
;Cell_address = % XL_App.ActiveCell.Address[1,1]
;Cell_value = % XL_App.ActiveCell.value
Cell_address := % ComObjActive("Excel.Application").ActiveCell.Address[1,1]
Range_address := % ComObjActive("Excel.Application").Selection.Address(0, 0)
;;DEBUG
;msgbox % Cell_address
;msgbox % Range_address
ExcelActions_HAlign(XL_App, RG:=Range_address, h:=2)
Return
;-------------------------------------------------------------
I modified Joe's XL_Format_HAlign so that it will take whatever cell(s) are selected, instead of having to define the range first:
Code: Select all
;-------------------------------------------------------------
ExcelActions_HAlign(ByRef XL, RG="", h="2"){
Cell_address = % XL.ActiveCell.Address[1,1]
Range_address := % ComObjActive("Excel.Application").Selection.Address(0, 0) ;This works for one or more cells
IfEqual,h,1,Return, XL.Application.ActiveSheet.Range(Range_address).HorizontalAlignment:=-4131 ;Left
IfEqual,h,2,Return, XL.Application.ActiveSheet.Range(Range_address).HorizontalAlignment:=-4108 ;Centre
IfEqual,h,3,Return, XL.Application.ActiveSheet.Range(Range_address).HorizontalAlignment:=-4152 ;Right
}
;-------------------------------------------------------------