2

I am new to Visual Basic. I am trying to use the Selection datatype in VBA for an array. However, when I select more than 256 items, they no longer display in the debugger. For example, it knows that the count is 590 items, but it only actually registers 256 as items. Is that the limit? If so, how do I change my code to account for that? I would like to be able to select as many items as possible. Here is a snippet of my current code:

Dim Selection As Selection

Set Selection = currentExplorer.Selection

Print #n, Now & ": " & "Starting count on items in selection: " & Selection.Count

For Each obj In Selection
Set olItem = obj

I think I'm getting an overflow here because after 255 emails, the categories start displaying more than one, which is not what it is supposed to do:

emailCategory = olItem.Categories
Print #n, Now & ": " & "Email Category: " & emailCategory

I looked at the possible duplicate question. I don't want this to just work in the debugger. This is affecting my code in general and is miscategorizing items as things they should not be categorized as. (By categorized, I mean the categories you can add in Outlook.)

debugger

Please let me know if I need to add more context or anything. I will try to do my best. Thanks.

  • 1
    `but it only actually registers 256 as items` - how do you know that? – GSerg Nov 21 '19 at 10:28
  • @GSerg I'll attach proof. I found it in the debugger. – carmen.sandiego Nov 21 '19 at 10:30
  • @GSerg Please don't close my question. I looked at the duplicate and it doesn't answer what I'm trying to do. Can you reopen mine please? – carmen.sandiego Nov 21 '19 at 10:39
  • It does answer the question. The answer is No, you cannot do that. You cannot affect how the VBA debugger works. I guess you could exploit the fact there is no such limitation for arrays, so declare an array of Outlook objects, copy the items into it from Selection and add a watch on the array instead of the collection. – GSerg Nov 21 '19 at 10:39
  • @GSerg Then how do I account for more than 256 items? I'm trying to select and go through an extensive amount of emails. – carmen.sandiego Nov 21 '19 at 10:41
  • You don't need the debugger to programmatically operate on collections. Select, go, do whatever you need. You just won't be able to inspect the collection in the debugger. – GSerg Nov 21 '19 at 10:42
  • @GSerg Sorry for extensive comments, I don't have enough rep to move this to chat. There is an overflow in my code that I need to fix. That is why I checked the debugger. How do I fix the overflow? – carmen.sandiego Nov 21 '19 at 10:43
  • An overflow exception has nothing to do with the number of elements the VBA debugger can display at a time. You [should have](https://meta.stackexchange.com/q/66377/147640) shown the line of code that causes the overflow instead. – GSerg Nov 21 '19 at 10:46
  • @GSerg Updated the question. Should I just make a new question at this point? – carmen.sandiego Nov 21 '19 at 10:51
  • 1
    Yes please, that would be better. In the new question please not only show the exact code that causes the error, but also the exact error message. "I think I'm getting an overflow" is not good enough. There either is an exception or there isn't, and when there is, it highlights the line. If you just have wrong output, without an exception occurring, that's a different problem still, but you should also describe it properly (what the output is, what it should be instead). – GSerg Nov 21 '19 at 10:52

0 Answers0