0

我有这段代码,我可以在每个外循环结束时显示消息。我想在假设数组或类似结构的某些列表中捕获所有这些消息,然后最后想将这些消息中的每一个显示到一个 msgbox 中。如果有人可以帮助我,将不胜感激。谢谢。

For Each objNavFolder In objNavGroup.NavigationFolders
    SkippedItemCounter = 0
    If oItems.Count = 0 Then
        MsgBox "No Appointments items in " & objNavFolder.DisplayName & "'s folder"
    Else
        NextRow = NextRow + 1
        For Each MyItem In oItems
             If MyItem = "" Then
                 SkippedItemCounter = SkippedItemCounter + 1
             End If
             'some code here
        Next 
        Set objExpl = _colExpl.Add(objFolder, olFolderDisplayNormal)
        NextRow = NextRow - 1
    End If
    MsgBox "No. of items= "&SkippedItemCounter&"skipped from"&objNavFolder.DisplayName&""
Next 
End If
End If
End If
4

2 回答 2

2

而不是调用 msgboxes,而是创建一个字符串并继续添加消息 - 在代码 msgbox(yourString) 的末尾

例如 decalare 在主子之前的字符串

Dim yourFinalMessage As String ' or Dim yourFinalMessage$

代替

MsgBox "No Appointments items in " & objNavFolder.DisplayName & "'s folder"

yourFinalMessage = yourFinalMessage & vbCrLf & & _ 
             "No Appointments items in " & objNavFolder.DisplayName & "'s folder"

继续这样做直到循环结束。

在循环结束时说

msgbox YourFinalMessage 
于 2013-04-30T11:31:22.183 回答
0

不确定是否完全理解您想要的内容,但您可以尝试将其添加到模块中:

Option Explicit

Dim globalMsg as String
globalMsg = ""

Function customMsg(msg as String)
    MsgBox msg
    globalMsg = globalMsg & VbCrLf & msg
End Function

只需调用customMsg("Your Message")以显示一个 MsgBox,最后调用MsgBox globalMsg以将所有消息显示为一条消息(每行一条)。有很多其他方法可以做到这一点,这取决于你。如果您需要任何进一步的帮助,请更加明确。

于 2013-04-30T14:15:58.030 回答