une


It seems that there are two ways to set a property. Using the example of a label on a userform, the property for it's initial caption and colour can be set by editing the appropriate fields in the properties window. That is easy, but these initial settings do not show up in any code on the userform. How could the initial settings for the caption and colour properties of the label be set via code in the userform I cannot work it out using the help screens. Thanks.






Re: Setting properties

Andy Pope


Hi,

The usual place for setting control properties in the userforms Initialize event.

Private Sub UserForm_Initialize()

With Label1
.Caption = "Hello World"
.ForeColor = vbRed
End With
End Sub







Re: Setting properties

une

Thanks. Why do you not see the code that initializes an object's properties as detailed in the properties GUI window I can change the colours, fonts, captions and many other properties of an object in this window, but these changes do not seem to be reflected in code anywhere that I can see. Is this code hidden somewhere I would have guessed that all the settings detailed in an object's properties window would be replicated in code somehwere, and that changing the properties via the GUI window was just a shortcut, rather than altering the actual code.





Re: Setting properties

Andy Pope

The details are stored within the workbook. The VBE probably hides any 'code', more likely just property values.
If you export a userform 2 files are created a frm and frx. The frm file is a text file and if you look at this in notepad you can see some of the project level settings which are also only exposed via property and dialog windows.
The frx file is a binary file which contians the details of controls and code.





Re: Setting properties

une

So it seems that object settings are either stored within the "workbook" or explicitly set via an xyz_Initialize() sub routine. I'm not really sure what a "workbook" is and how it fits into the whole VBA picture. I am used to C++ & Java where everything is contained in the source code. I am finding that having some stuff that helps the program run stashed away somewhere separate from the source code is causing me a little confusion. I am slowly getting more familiar with the VBA environment and am sure it is a powerful, and probably more importantly, a widely used tool. The development environment seems quite complex with many dark recesses I am yet to discover. I appreciate your timely and thoughtful responses.