finaljustice
Board Regular
- Joined
- Oct 6, 2010
- Messages
- 175
Hello,
I've been finishing a project here, it is based on userforms. I am now trying to make it easy for ppl to update the userform captions which will change acording to the years.
What I wish to do is to retrieve my Label Captions from Worksheet cells. My code seems to be "fine" but when the userform loads up there are no captions.
Here is the process through which my userform goes to Load since it will resize according the computer screen. (Pressing F8 step by step)
P1:
followed by:
P2:
Then back to
Any suggestions to why I'm loosing the caption as the userform loads?
PS: I've added those "notes" inside the code but on my actual coding there are none.
Ty for your attention.
I've been finishing a project here, it is based on userforms. I am now trying to make it easy for ppl to update the userform captions which will change acording to the years.
What I wish to do is to retrieve my Label Captions from Worksheet cells. My code seems to be "fine" but when the userform loads up there are no captions.
Here is the process through which my userform goes to Load since it will resize according the computer screen. (Pressing F8 step by step)
P1:
Code:
Private Sub UserForm_Initialize()
Call FormatUserForm(Me.Caption) 'goes collect info of the monitor to resize
UserForm1.Label24.Caption = Sheets("Fonte").Range("$H$7").Text
End Sub
followed by:
P2:
Code:
Private Declare Function FindWindowA Lib "USER32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLongA Lib "USER32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongA Lib "USER32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Option Explicit
Sub FormatUserForm(UserFormCaption As String)
Dim hWnd As Long
Dim exLong As Long
hWnd = FindWindowA(vbNullString, UserFormCaption)
exLong = GetWindowLongA(hWnd, -16)
If (exLong And &H20000) = 0 Then
SetWindowLongA hWnd, -16, exLong Or &H20000
Else
End If
End Sub
Then back to
Code:
Private Sub UserForm_Initialize()
Call FormatUserForm(Me.Caption)
UserForm1.Label24.Caption = Sheets("Fonte").Range("$H$7").Text
' when the code P2 ends it returns to this point. From the code seems to work because
when I place my mouse ontop of "UserForm1.Label24.Caption" it actually has retrieved
the text from the cell, in this case the year 2008.
'when this code ends the userform loads....
End Sub
Any suggestions to why I'm loosing the caption as the userform loads?
PS: I've added those "notes" inside the code but on my actual coding there are none.
Ty for your attention.