You don't have to select ranges programmatically to effect a
format to an area of cells. The Range object will do the
trick. "Selection" is used to refer to what's selected in
the user interface and "Select" is used to select a range of
cells in the user interface. Programmatically, you only
need point a Range object variable to a range of cells and
then apply the format you want to the Range object.
Below is an example.
Incidentally, I have no expertise in sorting.
It looks complicated in help.
' Excel objects:
Dim objXL As Excel.Application
Dim objWBK As Excel.Workbook
Dim objWS As Excel.Worksheet
Dim objRNG1 As Excel.Range
Dim objRNG2 As Excel.Range
' Start Excel:
Set objXL = New Excel.Application
objXL.Visible = True
' Open the WorkBook:
Set objWBK = objXL.Workbooks.Open(strWorkBookPath)
' Point to Worksheet
Set objWS = objWBK.Worksheets(1)
' Point to a range:
Set objRNG1 = objWS.Range("A1", "Z1")
' Put borders around each cell:
For Each objRNG2 In objRNG1.Cells
objRNG2.BorderAround xlContinuous, _
xlMedium, xlColorIndexAutomatic, _
RGB(255, 255, 255)
Next
' Format the whole range:
With objRNG1
' Shade each cell:
With .Interior
.ColorIndex = 15
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
With .Font
.Size = 12
.Bold = True
.FontStyle = "Arial"
End With
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
' Format various columns in differnt
' number formats:
' General number format:
Set objRNG1 = objWS.Columns(2)
objRNG1.NumberFormat = "General"
' Currency format
' (positive in black, negative in red)
Set objRNG1 = objWS.Columns(3)
objRNG1.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
' Time format:
Set objRNG1 = objWS.Columns(4)
objRNG1.NumberFormat = "hh:mm:ss"
' Point to top left corner:
Set objRNG1 = objWS.Range("A1")
' Expand range to embrace all contiguous data:
Set objRNG1 = objRNG1.CurrentRegion
' Sort data:
' Put cursor on the words "Sort" and
' "SortSpecial", press F1, and read help
' topics to determine which parameters to
' use after the words Sort and SortSpecial.
objRNG1.Sort
' or:
objRNG1.SortSpecial
Geoff
message
I guess that's where I'm having problems....the code I
would use inside an
Excel macro, doesn't work from inside Access. Especially
borders -
everything I try it tells me it is not supported.
.