LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default How to add Chart_Activate code using VBA

Hi,
I have a macro that creates a workbook with some pivot charts.
I want to have the macro write code to call a procedure whenever the pivot
chart is activated but it doesn't seem to work.

All I really want to do is add the following code in the Chart - Activate
Event Procedu
" Call Format_Pivot_Chart"
("Format_Pivot_Chart" is a routine already in the workbook.)

I've used the code below to successfully add code to the Thisworkbook.Open
See partial code below the routine to see what's really different.

Thanks for any help,
MikeZz


Public Sub A85_Transfer_Macros_Chart_Activate(shtChart As Worksheet)
Const sStr As String = "C:\Temp\CodeChartActivate" & shtChart & ".txt"

Dim VBAEditor As VBIDE.VBE
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character
Dim FileNum
Dim resultstr

Application.EnableEvents = False

Dim VBAEditor As VBIDE.VBE
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character

Set VBProj = destWb.VBProject

Set VBComp = VBProj.VBComponents(shtChart.CodeName)
Set CodeMod = VBComp.CodeModule
With CodeMod
LineNum = .CreateEventProc("Activate", "Chart")
LineNum = LineNum + 1
.InsertLines LineNum, " Call Format_Pivot_Chart"
End With

Set CodeMod = Nothing
Set VBComp = Nothing
Set VBProj = Nothing
Set VBAEditor = Nothing

Application.EnableEvents = True

End Sub


PARTIAL CODE USED TO WRITE TO Thisworkbook.Open

Set VBProj = destWb.VBProject

Set VBComp = VBProj.VBComponents("ThisWorkbook")
Set CodeMod = VBComp.CodeModule

With CodeMod
LineNum = .CreateEventProc("Open", "Workbook")
LineNum = LineNum + 1
.InsertLines LineNum, " Call OpenForm"
End With

 
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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does ker_01 Excel Programming 6 October 3rd 08 09:45 PM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM
Chart_Activate not running when workbook opened [email protected] Excel Programming 2 September 2nd 06 07:42 PM


All times are GMT +1. The time now is 07:12 PM.

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"