Advertisement
Guest User

sub3

a guest
Apr 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. Sub Charts3()
  2. ' This sub shows some other things you can do to
  3. ' fine tune charts. In general, you learn some of the
  4. ' coding from recording, some from the Object Browser.
  5.  
  6. Dim red1 As Integer, green1 As Integer, blue1 As Integer
  7. Dim red2 As Integer, green2 As Integer, blue2 As Integer
  8. Dim chtObj As ChartObject
  9. Dim cht As Chart
  10. Dim ser As Series
  11. Dim ax As Axis
  12.  
  13. ' Use this next statement so that the random colors chosen
  14. ' later on will be different from run to run.
  15. Randomize
  16.  
  17. Set chtObj = wsDistrict12.ChartObjects("District 12")
  18. Set cht = chtObj.Chart
  19.  
  20. With cht
  21. ' Change properties of plot area.
  22. With .PlotArea.Format.Fill
  23. MsgBox "The plot area will be changed from blank to gray."
  24. .ForeColor.ObjectThemeColor = msoThemeColorBackground1
  25. .ForeColor.Brightness = -0.150000006
  26. .Visible = msoTrue
  27. End With
  28.  
  29. MsgBox "It will now be restored to blank."
  30. .PlotArea.Format.Fill.Visible = msoFalse
  31.  
  32. ' Remove and restore grid lines.
  33. Set ax = .Axes(xlValue)
  34. With ax.MajorGridlines.Format.Line
  35. MsgBox "The horizontal grid lines will be deleted."
  36. .Visible = msoFalse
  37.  
  38. MsgBox "They will now be restored."
  39. .Visible = msoTrue
  40. End With
  41.  
  42. ' Generate two random colors (with no green in the first,
  43. ' no red in the second).
  44. MsgBox "The two series will now change to some random colors."
  45. red1 = Int(Rnd * 255)
  46. green1 = 0
  47. blue1 = Int(Rnd * 255)
  48. red2 = 0
  49. green2 = Int(Rnd * 255)
  50. blue2 = Int(Rnd * 255)
  51.  
  52. ' Change some colors in the chart.
  53. Set ser = .SeriesCollection(1)
  54. With ser
  55. .Border.Color = RGB(red1, green1, blue1)
  56. .MarkerBackgroundColor = RGB(red1, green1, blue1)
  57. .MarkerForegroundColor = RGB(red1, green1, blue1)
  58. End With
  59. Set ser = .SeriesCollection(2)
  60. With ser
  61. .Border.Color = RGB(red2, green2, blue2)
  62. .MarkerBackgroundColor = RGB(red2, green2, blue2)
  63. .MarkerForegroundColor = RGB(red2, green2, blue2)
  64. End With
  65. End With
  66. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement