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: 19
Default Code "crashes" after dynamically adding control to worksheet

My code creates a worksheet and adds a forms commandbutton, both "on the fly".

Dim ws As Worksheet
Dim lStartLine As Long
Dim sCode as String
Set ws = Sheets("NewWorksheet")


My question is two parts:

PART I: For the coding below that doesn't work, I would like to know why.

If I use the following code to create the button, the code is added
successfully:
With ActiveWorkbook.VBProject.VBComponents(ws.CodeName) .CodeModule
lStartLine = .CountOfLines + 1
.InsertLines lStartLine, sCode
End With

If I use this code, it crashes:
Set wsVBComp = ActiveWorkbook.VBProject.VBComponents(ws.CodeName)
wsVBComp.CodeModule.AddFromString sCode

If I use this code, I get a "Runtime error 57: device I/O error" (all on one
line):
ActiveWorkbook.VBProject.VBComponents
(ws.CodeName).CodeModule.AddFromFile sCode

If I use this code, a dialog window pops up saying "cant enter break mode at
this time" or IF it doesn't crash, adds code to module but then form doesn't
show
Excel.Application.VBE.ActiveVBProject.VBComponents (again all on one
line)(ws.CodeName).CodeModule.AddFromString sCode

PART II (a two-part question):

In the code above that DOES work:

A: Control does not return to calling procedure (UserForm_Initialize).

B: The code ("Private Sub cmdDelete_Click") for the created button does
appear in the code module for the created worksheet. But if I click on the
button on the worksheet, I get the following dialog box message:

"The macro 'WorkbookName.xls!Sheet7cmdDelete_Click' cannot be found."

There is nothing unusual about the code itself except for the above-noted.

Thanks,
--e






 
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
adding a "relationship code" to a worksheet pat67 Excel Worksheet Functions 4 January 18th 10 09:18 PM
Adding values in first "X" number of rows dynamically MattyP Excel Worksheet Functions 3 April 15th 09 06:13 PM
Adding watch point "Application.Caller" crashes Edsel 97. [email protected] Excel Programming 3 January 17th 08 04:52 PM
Adding "Add-Ins..." control to custom tooolbar Sandusky[_2_] Excel Programming 1 September 28th 07 12:08 AM
adding items to combobox using "Tag" control to limit bob cochran Excel Programming 5 September 10th 03 05:21 PM


All times are GMT +1. The time now is 03:00 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"