If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#2
|
|||
|
|||
My code chart is looping
Keawee -
I think Tushar meant to put EnableEvents=True before End Sub. For part 2, look at the Workbook_BeforeClose event. - Jon ------- Jon Peltier, Microsoft Excel MVP http://www.geocities.com/jonpeltier/Excel/index.html _______ Tushar Mehta wrote: When you create the chart with Charts.Add, XL creates a chartsheet. With the Location statement, the chart is moved from its own sheet to the specified worksheet. This activates the Worksheet, which triggers the code in Worksheet_Activate all over again. One way around it is to create the chart with code such as: Sub myChart() If Not TypeOf ActiveSheet Is Worksheet Then Exit Sub ActiveSheet.ChartObjects.Add _ ActiveCell.Left, ActiveCell.Top, 300, 200 With ActiveSheet.ChartObjects(ActiveSheet.ChartObjects. Count).Chart .ChartType = xlColumnClustered .SetSourceData Source:=ActiveSheet.Range("A1:A3") End With '...Rest of code... End Sub Another way around it is to use something like: Private Sub Worksheet_Activate() Application.EnableEvents = False On Error GoTo errHandler myChart errHandler: Application.EnableEvents = False End Sub |
#3
|
|||
|
|||
My code chart is looping
He, he! The single most common programming mistake I make. Copying
and leaving alone the EnableEvents=False statement. -- Regards, Tushar Mehta, MS MVP -- Excel www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , says... Keawee - I think Tushar meant to put EnableEvents=True before End Sub. For part 2, look at the Workbook_BeforeClose event. - Jon ------- Jon Peltier, Microsoft Excel MVP http://www.geocities.com/jonpeltier/Excel/index.html _______ Tushar Mehta wrote: When you create the chart with Charts.Add, XL creates a chartsheet. With the Location statement, the chart is moved from its own sheet to the specified worksheet. This activates the Worksheet, which triggers the code in Worksheet_Activate all over again. One way around it is to create the chart with code such as: Sub myChart() If Not TypeOf ActiveSheet Is Worksheet Then Exit Sub ActiveSheet.ChartObjects.Add _ ActiveCell.Left, ActiveCell.Top, 300, 200 With ActiveSheet.ChartObjects(ActiveSheet.ChartObjects. Count).Chart .ChartType = xlColumnClustered .SetSourceData Source:=ActiveSheet.Range("A1:A3") End With '...Rest of code... End Sub Another way around it is to use something like: Private Sub Worksheet_Activate() Application.EnableEvents = False On Error GoTo errHandler myChart errHandler: Application.EnableEvents = False End Sub |
#4
|
|||
|
|||
My code chart is looping
That and ScreenUpdating. Then I wonder why the program misbehaves!
Tushar Mehta wrote: He, he! The single most common programming mistake I make. Copying and leaving alone the EnableEvents=False statement. |
Thread Tools | |
Display Modes | |
|
|