Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Write a button to run macro on *ANY* chart area clicked.

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro button gets bigger when clicked Snowskier Excel Discussion (Misc queries) 1 May 27th 10 09:36 PM
Change Macro button color after clicked Cong Nguyen Excel Discussion (Misc queries) 2 November 30th 07 02:55 PM
why is the chart displayed only when the chart area is clicked on? Vivien Charts and Charting in Excel 1 October 27th 06 04:29 PM
Pause macro, add form button to sheet, continue macro when button clicked! Flystar[_15_] Excel Programming 1 May 26th 04 09:45 AM
How to end macro on inital active worksheet containing macro button that was clicked Silverhawk1 Excel Programming 2 May 14th 04 03:58 PM


All times are GMT +1. The time now is 06:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"