Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Problem with Dynamically Writing Event Procedure

I'm using the following routine to add event procedures to a newly created
workbook wbOut from an existing workbook.

Private Sub AddEventProc(wbOut As Workbook)
'writes an event procedure to every sheet of the active workbook
On Error Resume Next
Dim ws As Worksheet
Dim LineNum As Long
For Each ws In wbOut.Worksheets
With wbOut.VBProject.VBComponents(ws.CodeName).CodeModu le
LineNum = .CreateEventProc("PivotTableUpdate", "Worksheet")
.InsertLines LineNum + 1, _
"Target.ColumnRange.ColumnWidth = 14" & vbCrLf & _
"Target.ColumnRange.WrapText = True"
End With
Next ws
End Sub

The problem is that the function seems to open up the Visual Basic Editor
and leave it open. I don't want my clients to see this when they run the
routine. Is there a way to stop the Visual Basic Editor opening up with
this routine or to programmatically shut it down once opened up.

Also, I've found that the function will very intermittently cause Excel 2003
to crash. I've studied the Pierson page on using code to write code, but I
haven't found a way yet that doesn't intermittently crash Excel. Anybody
have any suggestions?

Thanks,
Wayne C.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Problem with Dynamically Writing Event Procedure

I don't have a guess at why it crashes excel. But you could hide that VBE
window when you're done:

Application.VBE.MainWindow.Visible = False

And if you're adding the same code to all the worksheet modules, maybe you could
just use one procedu

Option Explicit

Private Sub AddEventProc(wbOut As Workbook)
'writes an event procedure to every sheet of the active workbook
'On Error Resume Next 'what causes the error???

Dim LineNum As Long

With wbOut.VBProject.VBComponents("thisworkbook").CodeM odule
LineNum = .CountOfLines + 1
.CreateEventProc "SheetPivotTableUpdate", "Workbook"
.InsertLines LineNum + 1, _
"sh.Target.ColumnRange.ColumnWidth = 14" & vbCrLf & _
"sh.Target.ColumnRange.WrapText = True"
End With

Application.VBE.MainWindow.Visible = False

End Sub

The Vision Thing wrote:

I'm using the following routine to add event procedures to a newly created
workbook wbOut from an existing workbook.

Private Sub AddEventProc(wbOut As Workbook)
'writes an event procedure to every sheet of the active workbook
On Error Resume Next
Dim ws As Worksheet
Dim LineNum As Long
For Each ws In wbOut.Worksheets
With wbOut.VBProject.VBComponents(ws.CodeName).CodeModu le
LineNum = .CreateEventProc("PivotTableUpdate", "Worksheet")
.InsertLines LineNum + 1, _
"Target.ColumnRange.ColumnWidth = 14" & vbCrLf & _
"Target.ColumnRange.WrapText = True"
End With
Next ws
End Sub

The problem is that the function seems to open up the Visual Basic Editor
and leave it open. I don't want my clients to see this when they run the
routine. Is there a way to stop the Visual Basic Editor opening up with
this routine or to programmatically shut it down once opened up.

Also, I've found that the function will very intermittently cause Excel 2003
to crash. I've studied the Pierson page on using code to write code, but I
haven't found a way yet that doesn't intermittently crash Excel. Anybody
have any suggestions?

Thanks,
Wayne C.


--

Dave Peterson
Reply
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
Writing a formula which dynamically generates results sandeep singh Excel Worksheet Functions 5 May 26th 08 04:12 PM
change event procedure benb Excel Programming 2 September 24th 04 09:22 PM
programming the VBE for a new event procedure mark kubicki Excel Programming 3 August 18th 04 04:43 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM
ComboBox Event Procedure problem Brent McIntyre Excel Programming 1 September 18th 03 02:01 PM


All times are GMT +1. The time now is 06:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"