Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Dynamically Adding Code to Buttons on an existing UserForm

Dear All;
I am attempting to add code to buttons on a userform that exists
as part of an excel add-in. I have created the rest of the code, and
it all works OK, however I have changed from a dynamically created
userform, created at design time, to an existing userform with
controls and sizes added at runtime so that I can password protect the
project.

Unfortunately, whereas in the dynamic userform, I could use the
following code:

Set frmPrintAll = ThisWorkbook.VBProject.VBComponents.Add(3)
With frmPrintAll

'... Rest of code to dynamically create size, buttons, etc
....'

With frmPrintAll.CodeModule
x = .CountOfLines
.InsertLines x + 1, "Sub CommandButton1_Click()"
.InsertLines x + 2, " intClicked=-1"
.InsertLines x + 3, " Unload Me"
.InsertLines x + 4, "End Sub"

.InsertLines x + 5, "Sub CommandButton2_Click()"
.InsertLines x + 6, " intClicked=1"
.InsertLines x + 7, " Unload Me"
.InsertLines x + 8, "End Sub"
End With

When I attempt to modify the .CodeModue on the non-dynamically
created userform, nothing happens. I have a dimension statement at the
start of the code, which is accessed in the following way:

dim frmPrintAll as new frmPrintAll

I have tried created static code with the above details in them,
however when you click on the buttons, despite them being called
CommandButton1 and CommandButton2 (As far as I can tell, anyway)
nothing happens.

Does anybody have any solutions to this puzzling problem? Any
response will be much appreciated.

Peter Street
OLE Alliance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dynamically Adding Code to Buttons on an existing UserForm

If you protect your code, you won't be able to add code anyway. When a
project is locked, it is locked. You can't modify it any vbe aspect of it
with code.

--
Regards,
Tom Ogilvy


Peter Street wrote in message
om...
Dear All;
I am attempting to add code to buttons on a userform that exists
as part of an excel add-in. I have created the rest of the code, and
it all works OK, however I have changed from a dynamically created
userform, created at design time, to an existing userform with
controls and sizes added at runtime so that I can password protect the
project.

Unfortunately, whereas in the dynamic userform, I could use the
following code:

Set frmPrintAll = ThisWorkbook.VBProject.VBComponents.Add(3)
With frmPrintAll

'... Rest of code to dynamically create size, buttons, etc
...'

With frmPrintAll.CodeModule
x = .CountOfLines
.InsertLines x + 1, "Sub CommandButton1_Click()"
.InsertLines x + 2, " intClicked=-1"
.InsertLines x + 3, " Unload Me"
.InsertLines x + 4, "End Sub"

.InsertLines x + 5, "Sub CommandButton2_Click()"
.InsertLines x + 6, " intClicked=1"
.InsertLines x + 7, " Unload Me"
.InsertLines x + 8, "End Sub"
End With

When I attempt to modify the .CodeModue on the non-dynamically
created userform, nothing happens. I have a dimension statement at the
start of the code, which is accessed in the following way:

dim frmPrintAll as new frmPrintAll

I have tried created static code with the above details in them,
however when you click on the buttons, despite them being called
CommandButton1 and CommandButton2 (As far as I can tell, anyway)
nothing happens.

Does anybody have any solutions to this puzzling problem? Any
response will be much appreciated.

Peter Street
OLE Alliance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Dynamically Adding Code to Buttons on an existing UserForm

Thanks very much, Tom. I don't suppose you know of any way around
this? I'm trying to set this up so that it can be used by a number of
people, quite a few have "Technical" expertise - in other words, they
are experienced enough to fiddle with the code, and not experienced
enough to realise that doing such can cause silly things to happen
(Like trying to print out the normal.dot file - Excel didn't really
like that).

Again, thanks for the response.
--
Peter Street
OLE Alliance.

"Tom Ogilvy" wrote in message ...
If you protect your code, you won't be able to add code anyway. When a
project is locked, it is locked. You can't modify it any vbe aspect of it
with code.

--
Regards,
Tom Ogilvy


Peter Street wrote in message
om...
Dear All;
I am attempting to add code to buttons on a userform that exists
as part of an excel add-in. I have created the rest of the code, and
it all works OK, however I have changed from a dynamically created
userform, created at design time, to an existing userform with
controls and sizes added at runtime so that I can password protect the
project.

Unfortunately, whereas in the dynamic userform, I could use the
following code:

Set frmPrintAll = ThisWorkbook.VBProject.VBComponents.Add(3)
With frmPrintAll

'... Rest of code to dynamically create size, buttons, etc
...'

With frmPrintAll.CodeModule
x = .CountOfLines
.InsertLines x + 1, "Sub CommandButton1_Click()"
.InsertLines x + 2, " intClicked=-1"
.InsertLines x + 3, " Unload Me"
.InsertLines x + 4, "End Sub"

.InsertLines x + 5, "Sub CommandButton2_Click()"
.InsertLines x + 6, " intClicked=1"
.InsertLines x + 7, " Unload Me"
.InsertLines x + 8, "End Sub"
End With

When I attempt to modify the .CodeModue on the non-dynamically
created userform, nothing happens. I have a dimension statement at the
start of the code, which is accessed in the following way:

dim frmPrintAll as new frmPrintAll

I have tried created static code with the above details in them,
however when you click on the buttons, despite them being called
CommandButton1 and CommandButton2 (As far as I can tell, anyway)
nothing happens.

Does anybody have any solutions to this puzzling problem? Any
response will be much appreciated.

Peter Street
OLE Alliance.

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
buttons and boxes in userform Larry Sartoris Excel Discussion (Misc queries) 3 January 20th 06 04:39 PM
Dynamically create worksheets in Excel based off existing data? tlozier Excel Discussion (Misc queries) 1 September 10th 05 12:25 AM
How can I create and display a chart dynamically on a UserForm wi. cc Charts and Charting in Excel 1 February 14th 05 02:44 PM
How to get Maximize and Minimize buttons on Userform TBA[_2_] Excel Programming 1 September 9th 03 08:13 PM
How to add textbox/buttons to an UserForm Terence[_2_] Excel Programming 2 August 7th 03 08:56 AM


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