I have a userform that dynamically creates checkboxes for files in a chosen folder. How do I access the values of these checkboxes another sub?
Userform2.png
Sub for selecting folder and listing the check boxes is below
Sub SelectFolder()
Dim fldr, xlApp
Dim saveName
Dim nameLength
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim i As Integer
Dim j As Integer
Dim chkBox As MSForms.CheckBox
Dim slashLocation
Dim nameLocation
Dim partialDisplayNameLoc
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set file = xlApp.FileDialog(4) 'msoFileDialogFolderPicker
With file
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = "C:\"
If .Show = -1 Then foldername = .SelectedItems(1)
End With
i = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(foldername)
For Each oFile In oFolder.Files
strName = CStr(oFile)
slashLocation = InStrRev(strName, "\")
nameLocation = Len(strName) - slashLocation
displayName = Right(strName, nameLocation)
If Right(strName, 4) = ".dxf" Then
Set chkBox = selectFolderUserForm.Controls.Add("Forms.CheckBox.1")
chkBox.Caption = CStr(displayName)
'chkBox.Name = "CheckBox" & "i" '------------> Here is where I am trying to name the checkboxes to be able to access value from different sub
chkBox.Left = 5
chkBox.Top = 5 + ((i - 1) * 20)
chkBox.Value = True
chkBox.Font.Size = 10
chkBox.AutoSize = True
chkBox.WordWrap = False
i = i + 1
End If
Next oFile
End Sub
Sub Process()
'If CheckBox1.Value = True Then
'MsgBox ("Checked")
'End If
End Sub
Bookmarks