Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Programmatically Creating Worksheet Event
I'm running Excel XP with the latest service packs on WinXP SP2.
I'm using the following code to import a pivot table event to all the worksheets of an open workbook 'temp.xls' (tip of the hat to Pierson and others). ------------------------- Private Sub CallWriteEventProcedure Dim wb As Workbook, ws As Worksheet, arrTabs As Variant, i As Integer arrTabs = Split("Sheet1,Sheet2,Sheet3", ",") For i = 0 To UBound(arrTabs) Set wb = Workbooks("Temp.xls") Set ws = wb.Worksheets(arrTabs(i)) WriteEventProcedure wb, ws Next End Sub Private Sub WriteEventProcedure(wb as workbook, ws as worksheet) Dim strVBAFilesDir As String strVBAFilesDir = ThisWorkbook.Path & "\" & "VBA Files" wb.VBProject.VBComponents.Item(ws.CodeName).CodeMo dule.AddFromFile strVBAFilesDir & "\" & "PivotTableColumnEvent.txt" End Sub ------------------------- The problem is that Excel keeps crashing when I run it. I've tried rewriting it in lots of different ways (I've run a lot of newgroupsearches on the problem) but without solving the crashing problem. Is 'vbComponents' inherently flaky (it's not well documented in the help files) or is there a bullet proof solution to my problem? Thanks, Wayne C. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
help creating new hyperlinks programmatically | Links and Linking in Excel | |||
Programmatically Add Worksheet Event | Excel Programming | |||
Event Procedures: Event on Worksheet to fire Event on another Worksheet | Excel Programming | |||
Creating/Destroying Toolbars Programmatically | Excel Programming | |||
Creating Sub CommandButton1_Clk programmatically | Excel Programming |