VBA / Class Module Help

PhilPeel

New Member
Joined
Feb 18, 2016
Messages
6
Hi

Struggling with something that hopefully someone can assist with.

I have a form that loads data from an Excel workbook, then dynamically creates labels using this data.

I need to be able to click on the labels to then perform an action.

ie if I click on label 1 I want to be able to open file 1, if I click on label 2 open file 2 etc..

this is my code
Code:
Option Explicit
Dim MaxLines As Integer
Dim LC As Integer
Dim JobNo(200) As MSForms.Control
Private Sub UserForm_Initialize()

Call LoadData

Call Update

End Sub
Sub LoadData()
    
    Workbooks.Open FileName:="s:\Work\Order Log.xlsx"
    
    LC = 1
    Do
    
        LC = LC + 1
        
    Loop Until Cells(LC, 1) = ""
    
    MaxLines = LC - 1

    Call Draw
   
    LC = 1
    
    Do
    
            JobNo(LC).Caption = Cells(LC, 1)
    
            LC = LC + 1

    Loop Until LC > MaxLines

    ActiveWorkbook.Close savechanges:=False

End Sub
Private Sub Update()

LC = 1
    
    Do
        
        With JobNo(LC)
            .Top = LC * 20
            .BorderStyle = 1
            .Height = 18
            .Left = 0
            .SpecialEffect = fmSpecialEffectRaised
            .BackColor = &HC0C0C0
        End With
        
        LC = LC + 1

    Loop Until LC > MaxLines

End Sub

Private Sub Draw()

LC = 1

    Do
        Set JobNo(LC) = Me.Controls.Add("Forms.Label.1")
        
        LC = LC + 1
        
    Loop Until LC > MaxLines
    
End Sub

Can anyone show me how to create a class so that I can achieve this?

thanks in advance....

Phil
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

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