ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm_Initialize (https://www.excelbanter.com/excel-programming/358826-re-userform_initialize.html)

Bob Phillips[_6_]

UserForm_Initialize
 
I agree Bart.

I tend to have a procedure outside of the userform that loads the form and
does all the initialise biz, then shows it. I find it more manageable.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"RB Smissaert" wrote in message
...
No particular question really, but just an observation and maybe somebody
has some opinion about this.
When you have a complex VBA project with userforms it can be difficult to
control when the UserForm_Initialize
event will be triggered. I have found now that it is just much easier not

to
use this at all and make a procedure
that runs all the code that normally would go into UserForm_Initialize.
Then you can run this procedure whenever you want, for example after Load
UserForm.
Doing this gives you me more control and avoids problems.

RBS




RB Smissaert

UserForm_Initialize
 
Hi Bob,

Thanks for confirming.
In fact I still had one thing in UserForm_Initialize.
Simplified:

Private WithEvents xlApp As Excel.Application

Private Sub UserForm_Initialize()

Set xlApp = Excel.Application

End Sub

But I have now taken this out as well:

Private lMainFormHwnd As Long
Private WithEvents xlApp As Excel.Application

Public Property Let propFormHwnd(lHwnd As Long)

lMainFormHwnd = lHwnd

Set xlApp = Excel.Application

End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lMainFormHwnd
End Property

Where the property propFormHwnd gets set in the procedure that replaces
UserForm_Initialize.
I needed the hwnd of this form in any case so I used this the Property Let
procedure.

RBS


"Bob Phillips" wrote in message
...
I agree Bart.

I tend to have a procedure outside of the userform that loads the form and
does all the initialise biz, then shows it. I find it more manageable.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"RB Smissaert" wrote in message
...
No particular question really, but just an observation and maybe somebody
has some opinion about this.
When you have a complex VBA project with userforms it can be difficult to
control when the UserForm_Initialize
event will be triggered. I have found now that it is just much easier not

to
use this at all and make a procedure
that runs all the code that normally would go into UserForm_Initialize.
Then you can run this procedure whenever you want, for example after Load
UserForm.
Doing this gives you me more control and avoids problems.

RBS






All times are GMT +1. The time now is 08:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com