VB6 and excel useform

User avatar
sal21
PlatinumLounger
Posts: 4357
Joined: 26 Apr 2010, 17:36

VB6 and excel useform

Post by sal21 »

To save time, and not recreate my 21 userform, i have imported in vb6 classic a userform of Excel.
In the internal of this userform i have a frame1 with 34 Lable.
i loop, in my old excel project with this:

Sub RESET_CAPTION()

Dim CTL As Control
For Each CTL In Frame1.Controls
TEST = CTL.Name
If Left(TEST, 1) = "B" Then
CTL.ForeColor = &H0&
End If
Next CTL

End Sub

no prob....

But in VB6 the code go in error in: For Each CTL In Frame1.Controls. error 13 type mismach

HELP ME!!!!

ref:http://www.eileenslounge.com/viewtopic. ... As+Control

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB6 and excel useform

Post by HansV »

In VB6, a frame control does not have a Controls collection. You can use the following instead:

Code: Select all

Sub RESET_CAPTION()
    Dim CTL As Control
    For Each CTL In Me.Controls
        If CTL.Container Is Frame1 Then
            TEST = CTL.Name
            If Left(TEST, 1) = "B" Then
                CTL.ForeColor = &H0&
            End If
        End If
    Next CTL
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4357
Joined: 26 Apr 2010, 17:36

Re: VB6 and excel useform

Post by sal21 »

HansV wrote:In VB6, a frame control does not have a Controls collection. You can use the following instead:

Code: Select all

Sub RESET_CAPTION()
    Dim CTL As Control
    For Each CTL In Me.Controls
        If CTL.Container Is Frame1 Then
            TEST = CTL.Name
            If Left(TEST, 1) = "B" Then
                CTL.ForeColor = &H0&
            End If
        End If
    Next CTL
End Sub
SAME ERROR in: For Each CTL In Me.Controls. error 13 type mismach

User avatar
HansV
Administrator
Posts: 78512
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB6 and excel useform

Post by HansV »

What happens if you remove the line

Code: Select all

    Dim CTL As Control
and then type it again (don't copy / paste)?

If that doesn't help, what if you change the above line to

Code: Select all

    Dim CTL As Object
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4357
Joined: 26 Apr 2010, 17:36

Re: VB6 and excel useform

Post by sal21 »

HansV wrote:What happens if you remove the line

Code: Select all

    Dim CTL As Control
and then type it again (don't copy / paste)?

If that doesn't help, what if you change the above line to

Code: Select all

    Dim CTL As Object

:music: You are The Champion...
Great Hans, only you!!!!

With ... As Object work a charm.
Tks.