Programatically adding code to a worksheet
Bob...
Tried what you wrote and changed "Sheet1" to a valid sheet in my
workbook.
When I ran it, received the following error.
Run-time error 57017
Event handler is invalid
Debug showed line containing Startline highlighted.
Any ideas?
Thanks
On May 19, 1:40*am, "Bob Phillips" wrote:
1.
Dim StartLine As Long
* * With ActiveWorkbook.VBProject.VBComponents("Sheet1").Co deModule
* * * * StartLine = .CreateEventProc("Click", "CommandButton1") + 1
* * * * .InsertLines StartLine, _
* * * * "Dim ans" & vbCrLf & _
* * * * " * ans = Msgbox( ""All OK"",vbYesNo)" & vbCrLf & _
* * * * " * If ans = vbNo Then Cancel = True"
* * End With
2. Yes
--
---
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my addy)
"Flashin thePan" wrote in ...
I've written a macro to add some controls (i.e. buttons) to a
worksheet (not form).
2 questions
1. How do I add the code for the controls, like 'Private Sub
CommandButton1_Click()', to the worksheet that contains the control
programatically.
2. does this code have to be attached to the sheet that contains the
controls?
Thanks- Hide quoted text -
- Show quoted text -
|