>I'm trying to control Excel from VFP. I can make the change in Excel but I can't figure out how to get VFP to control Excel to do the same thing.
>
>I need to change the formatting of one column of a spreadsheet.
>
>I used the macro recorder which gave me the following code:
>
> Columns("P:P").Select
> With Selection
> .HorizontalAlignment = xlLeft
> .Orientation = 0
> .AddIndent = False
> .IndentLevel = 0
> .ShrinkToFit = False
> .ReadingOrder = xlContext
> End With
>
>How can I change this to execute as VFP code?
>Note: the object reference to the spreadsheet is: loActiveSheet
>
>I got this far:
>
> WITH loActiveSheet
> .Columns("P:P").Select
> With Selection && this line fails to compile
> .HorizontalAlignment = xlLeft
> .Orientation = 0
> .AddIndent = .F. && false
> .IndentLevel = 0
> .ShrinkToFit = .F. && False
> .ReadingOrder = xlContext
> END WITH && this line fails to compile
> ENDWITH && loActiveSheet
>
>I can figure out the Excel constants, but I can't figure out how to convert the "With Selection" line.
>
>
>Thanks!
You don't need the selection. Selection is a range and you have the range.
WITH loActiveSheet.Columns("P:P")
.HorizontalAlignment = xlLeft
.Orientation = 0
.AddIndent = .F.
.IndentLevel = 0
.ShrinkToFit = .F.
.ReadingOrder = xlContext
ENDWITH
PS: If you really need selection then use:
oExcel.Selection
or:
loActiveSheet.Application.Selection
Cetin