Changing design time properties at runtime

D

Darv

Hi All,

Is it possible to change the design time property of an object at
runtime? In my case I am trying to make a button visible at runtime,
and keep the setting permanently once the macro finishes.

I asked a similar question earlier but didn't word it very well.

Thanks again

David
 
M

moon

UserForm1.CommandButton1.Visible = True / False

If you only want to them to be greyed out:

UserForm1.CommandButton1.Enabled = True / False
 
D

Darv

Hi,

This works until the macro is reset, when all the runtime property
changes are also reset to their design time values.

Anyone know how to get round this?

David
 
D

Darv

Problem sorted. See "Changing object properties permanently at runtime"
to see solution.

David
 
T

Tom Ogilvy

this is some sample code to make a permanent change to a userform using code
(this changed the caption on some commandbuttons):

Sub abc()
Dim vc As Object
Dim rng As Range, cell As Range
Dim i As Long
Set vc = ThisWorkbook.VBProject.VBComponents("UserForm1")
Set rng = Worksheets("Sheet1").Range("A1:A52")
i = 0
For Each cell In rng
i = i + 1
vc.Designer.Controls("CommandButton" & i) _
.Caption = Format(cell.Value, "mm_dd_yyyy")
Next
End Sub

I doubt you can do this while the form is displayed, but you could record
the runtime changes you made, then implement them with code like this after
you unload the form. Just remember that at some point, you will need to save
the workbook.
 
D

Darv

That's perfect thanks!

I had to run this code with the form unloaded, like you said. For
anyone else trying it you cannot (obviously) run this code from a
subroutine in the form, because you can't unload a form from within
itself (I don't think).

Cheers,

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top