Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Save a userform that has been created programmatically at runtime?

Is it possible to save a userform that has been created programmatically at
runtime, so that it is available for use at the next session, as if it were
created at design time?

This may sound like a strange query, but I have a userform with 133 text
boxes and 133 check boxes spread across two pages of a multipage control.
The boxes are added at runtime with the following code included in the
UserForm_Initialize event (the multipage control was added at design time -
only the text boxes and check boxes are added at runtime):

Private Sub UserForm_Initialize()

CountPagesReqd = Round(colCount / 72, 0)

CtrlLeftCoeff = 170
BoxWidth = 130
CheckLeftCoeff = 148

White = &H80000005
Pink = &H8080FF

If CountPagesReqd 2 Then
For p = 1 To CountPagesReqd - 2
Me.Controls("MultiPage1").Pages.Add
Next p
End If

For PageOnForm = 0 To CountPagesReqd - 1
For ColOnPage = 1 To 4
For a = 1 To 18
Ind = a + (ColOnPage - 1) * 18 + PageOnForm * 72
If Ind <= colCount Then
Set MyTextBox =
Me.Controls("MultiPage1").Pages(PageOnForm).Contro ls.Add _
("Forms.TextBox.1", "TextBox" & Format(Ind,
"00#"), True)
With MyTextBox
.Height = 18
.Left = 12 + (ColOnPage - 1) * CtrlLeftCoeff
.Top = 12 + (a - 1) * 30
.Width = BoxWidth
.Text = arrColHead(Ind)
If arrColHidden(Ind) Then
.BackColor = Pink
Else: .BackColor = White
End If
End With
Set MyChkBox =
Me.Controls("MultiPage1").Pages(PageOnForm).Contro ls.Add _
("Forms.CheckBox.1", "CheckBox" & Format(Ind,
"00#"), True)
With MyChkBox
.Height = 18
.Left = CheckLeftCoeff + (ColOnPage - 1) *
CtrlLeftCoeff
.Top = 12 + (a - 1) * 30
.Width = 12
If arrColHidden(Ind) Then .Value = True
End With
End If
Next a
Next ColOnPage
Next PageOnForm

Me.Controls("MultiPage1").Pages(1).Caption = "Columns 73 - " & colCount

Me.Controls("MultiPage1").Value = 0

End Sub

The problem with this is that if I want to make use of change events
associated with the text and check boxes I have to get down and dirty with
creating change events in code, as described by Chip Pearson in
http://www.cpearson.com/excel/vbe.aspx, which I'd rather not do!

I know I could create the form manually (at design time), which would
immediately make available their change events, but having to create, name
and align 266 boxes is rather daunting (laziness). What I'm hoping is that
there is some way of generating it largely through code at runtime and then
saving it as if it were designed manually. Hope this makes sense.

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default Save a userform that has been created programmatically at runtime?

What happens if you programmatically just save the file after creation?


"IanKR" wrote in message
...
Is it possible to save a userform that has been created programmatically
at runtime, so that it is available for use at the next session, as if it
were created at design time?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Save a userform that has been created programmatically at runtime?

"Harald Staff" wrote in message
. ..
What happens if you programmatically just save the file after creation?

It just reverts to how it was at design time - i.e. without the text boxes
and check boxes. That's the crux of the problem - the text and check boxes
that are created at runtime are never saved.

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
HOW CAN I WRITE A CODE TO A COMMANDBUTTON CREATED PROGRAMMATICALLY Kozete Excel Programming 1 June 11th 08 09:37 PM
problem with Excel file created programmatically bill Excel Programming 3 January 27th 08 10:58 PM
Event Code for Controls created at runtime... Robert Bruce[_2_] Excel Programming 0 December 6th 06 12:11 PM
Saving MSForm.Control (s) created at Runtime? Post Tenebras Lux Excel Programming 1 August 16th 06 07:31 AM
Data from Programmatically created Excel into SQL Server Raj Excel Programming 0 January 20th 05 10:03 PM


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