ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Programmatically Creating Worksheet Event (https://www.excelbanter.com/excel-programming/313662-programmatically-creating-worksheet-event.html)

The Vision Thing

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.




All times are GMT +1. The time now is 11:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com