Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have fairly versatile routine to identify the current type of
selected object for adjusting its color beyond the normal excel methods for color adjustments. May be this code will give you some ideas how to identify various selected objects with VBA code Sub AdjustColor() Dim colStart As Long Dim colID As Long Dim newColor As Long Dim myChart As String Dim selecName As String Dim sID As Long Dim pID As Integer Dim c As ChartObject Dim RGBval As RGB Dim shpR As ShapeRange On Error Resume Next If ActiveWorkbook Is Nothing Then MsgBox "Open workbook and try again!" ElseIf Selection Is Nothing Then pID = MsgBox("Make a selection and try again!", vbInformation, "Nothing selected!") Else Debug.Print TypeName(Selection) Debug.Print Selection.Name On Error GoTo 0 GetSelectionColor colStart, colID Select Case TypeName(Selection) Case "Range" newColor = PickNewColor(CDbl(colStart), colID) Selection.Interior.ColorIndex = colID Case "Series" sID = Selection.PlotOrder newColor = PickNewColor(CDbl(colStart), colID, , True) ActiveChart.SeriesCollection(sID).Select Selection.Interior.ColorIndex = colID Case "Point" sID = Selection.Parent.PlotOrder pID = pointID() newColor = PickNewColor(CDbl(colStart), colID, True, True) ActiveChart.SeriesCollection(sID).Points(pID).Sele ct Selection.Interior.Color = newColor Case "PlotArea" newColor = PickNewColor(CDbl(colStart), colID, , True) ActiveChart.PlotArea.Select Selection.Interior.ColorIndex = colID Case "ChartArea" newColor = PickNewColor(CDbl(colStart), colID, , True) ActiveChart.ChartArea.Select Selection.Interior.ColorIndex = colID Case "Legend" newColor = PickNewColor(CDbl(colStart), colID, True, True) ActiveChart.Legend.Select Selection.Interior.ColorIndex = ClosestColor(newColor) Case "LegendEntry", "DataTable", "Axis" MsgBox "Error: This object can't be colored!" Exit Sub Case "Rectangle", "Oval", "TextBox", "Drawing" On Error GoTo err_hdl Set shpR = Selection.ShapeRange On Error GoTo 0 ActiveWorkbook.Windows(1).Activate If ActiveSheet.Type = xlWorksheet Then ' shpR.Parent.TopLeftCell.Select ' does not work anymore in XL2007 shpR.Item(1).TopLeftCell.Select ' this works in XL2007 End If Debug.Print "in ", colID, colStart newColor = PickNewColor(CDbl(colStart), colID, True) Debug.Print "out ", colID, colStart, newColor shpR.Select With shpR.Fill .ForeColor.RGB = newColor End With Case Else MsgBox "Color picking for " & TypeName(Selection) & " via this add-in is not implemented." ' Stop End Select RGBval = buildRGB(colStart) Debug.Print "ActiveWorkbook.Colors(" & str(colID) & ") = RGB(" & RGBval.R & "," & RGBval.G & "," & RGBval.B & ")" perhapsupdateRGBtext End If Exit Sub err_hdl: MsgBox "Error: Please use standard Excel methods to modify the color of this object" End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro button gets bigger when clicked | Excel Discussion (Misc queries) | |||
Change Macro button color after clicked | Excel Discussion (Misc queries) | |||
why is the chart displayed only when the chart area is clicked on? | Charts and Charting in Excel | |||
Pause macro, add form button to sheet, continue macro when button clicked! | Excel Programming | |||
How to end macro on inital active worksheet containing macro button that was clicked | Excel Programming |