在VBA中使用string作为对象名称

我有一个六个checkbox,名为chk1chk2 ,…, chk6 ,我需要通过并列出标记的用户表单。 我想让它们一个接一个地列出来,如果有四个标记的框,这些框的标题将在A1:A4列出(即使它不是标记的四个第一个框)。

我试过这个代码:

 Dim i As Integer, n, As Integer n = 0 For i = 1 To 6 strChkName = "chk" & i If strChkName.Value Then Cells(1+n, 2) = strChkName.Caption n = n + 1 End If Next i 

但是,这不起作用。 可能是由于string和.Value事物的组合。 我似乎无法find任何关于这个。 这甚至有可能吗?

使用Nathan和Scott的意见,我设法使用VBA中的Controls()函数来解决这个问题。 在我的代码中使用,看起来像这样:

 Dim i As Integer, n, As Integer n = 0 For i = 1 To If Controls("chk" & i).Value Then Cells(1+n, 2) = Controls("chk" & i).Caption n = n + 1 End If Next i