I have a hierarchy chart (SmartArt) that represents a work breakdown structure, and I'm using VBA to manipulate the colors and text in the blocks as the user enters data about the project status. I implemented this by using the worksheet_change event to re-color the chart whenever the data on the sheet changed.
This worked well in an early demo to my user, so they asked me to expand it to the next level down in the breakdown structure. Unfortunately this expanded the hierarchy from ~dozen elements (nodes) to almost 80. Now when there is a change on the sheet, the worksheet_change handler takes 20-30 seconds to run. Not good....
I'm experimenting with different ways to speed this up, though it may be that this just isn't going to happen. One thing I thought I might do is to declare and set the object variable pointing to the chart only once instead of having it, as a local variable in the event handler, declared and set every time. Don't know if this would make a difference, but it's something to play with.
Anyway, I know how to declare global variables within modules, but since event handlers go on the sheet (or in the case of the workbook_open handler, with the workbook object) is there any way to do it? I tried putting:
on the workbook in the VBE and then
but I get an undefined variable error on objOKCShape.
Am I doing something wrong, or is this not doable?
Thanks!
This worked well in an early demo to my user, so they asked me to expand it to the next level down in the breakdown structure. Unfortunately this expanded the hierarchy from ~dozen elements (nodes) to almost 80. Now when there is a change on the sheet, the worksheet_change handler takes 20-30 seconds to run. Not good....
I'm experimenting with different ways to speed this up, though it may be that this just isn't going to happen. One thing I thought I might do is to declare and set the object variable pointing to the chart only once instead of having it, as a local variable in the event handler, declared and set every time. Don't know if this would make a difference, but it's something to play with.
Anyway, I know how to declare global variables within modules, but since event handlers go on the sheet (or in the case of the workbook_open handler, with the workbook object) is there any way to do it? I tried putting:
Code:
Option Explicit
Public objOKCShape As Shape
Private Sub workbook_open()
Set objOKCShape = Sheets("OKC").Shapes(1)
End Sub
on the workbook in the VBE and then
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Dim objShape As Shape
Dim i As Integer
Application.ScreenUpdating = False
With Sheets("OKC")
'Overall Rollup
'color
Call setColor("OKC", "O91", objOKCShape, 1)
but I get an undefined variable error on objOKCShape.
Am I doing something wrong, or is this not doable?
Thanks!