EXCEL VBA使用msgbox显示组合框中的项目

时间:2013-06-30 08:17:37

标签: excel vba

首先:初始化userform

我使用下面的代码初始化我的页面,以便填充我的组合框。

For Each cell In rangeA
    If cell.Value <> "" Then
        ComboBox1.AddItem cell.Value
    Else
    End If
Next

下一步

我有一个按钮来提示一个msgbox,它会调用我的组合框内的所有项目。我该怎么做呢?提前谢谢。

1 个答案:

答案 0 :(得分:2)

这可以按如下方式完成:

Private Sub ShowComboBoxAsMsgBox()
    Dim s As String
    Dim sep As String
    Dim i As Integer

    For i = 0 To Me.ComboBox1.ListCount - 1
        s = s & sep & Me.ComboBox1.List(i)
        sep = vbCrLf
    Next i

    MsgBox s, vbInformation, "my ComboBox"
End Sub
相关问题