Label Caption from Cell "found" & "lost"

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:
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.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top