Address selected topic, or topics, only

  • 2
  • Question
  • Updated 4 years ago
OK, I'm getting frustrated here. I am developing a couple of test macros that work on two different "scopes".

One works on only the single selected topic, and would probably be invoked by the topic context menu. The other on the collection of all selected topics, and would work off the map context menu.

The problem is in finding the proper code for getting a reference to each of those two slightly different parents topics (or collections).

Anyone have a sample of macro code to address each of those different situations? I have tried the map.range option, with no luck targeting just those items. I see lots of macro samples that process all topics on a map, but that is a bit of overkill for what I am trying to do.

Any help would be greatly appreciated!
Photo of Mike Danielski

Mike Danielski

  • 191 Posts
  • 6 Reply Likes

Posted 4 years ago

  • 2
Photo of Nigel Goult (Olympic & MIVAP)

Nigel Goult (Olympic & MIVAP)

  • 344 Posts
  • 133 Reply Likes
Mike,

Try this for a single topic:

Dim doc as Document
Dim topic as Topic
Set doc = activedocument
Set topic = doc.selection.primarytopic

Try this for multiple selection

Dim doc as Document
Dim selectedtopics as Selection
Dim topic as Topic
Set doc = ActiveDocument
Set selectedtopics = doc.selection

For each topic in selectedtopics
' do you thing
Next

You could just use the bottom code for both scenarios as the selection count will either be 1 or more.....

You might want to check that selectedtopics.count is more than 0 to make sure it has something and that what is selected is actually a topic.

Hope that helps.

Regards

A sleepy Nigel (its 3 am here :-) )
Photo of Mike Danielski

Mike Danielski

  • 191 Posts
  • 6 Reply Likes
Hi Nigel,

I have to admit, the debugger is less than stellar - I have gotten waaaay too spoiled by Visual Studio 2013! I am running into an error that doesn't make any sense, and I wonder if it does for you. I'm used to straight VB development in VS, FWIW.

If I have a topic selected in the map, and I run the following macro code (below) and it errors out on the red line, with the message "(10094) ActiveX Automation: Object var is 'Nothing'." That makes no sense to me because in the Watch window I test the various supporting objects or properties before that line is evaluated and they look good to me.

Thoughts?

Photo of Nigel Goult (Olympic & MIVAP)

Nigel Goult (Olympic & MIVAP)

  • 344 Posts
  • 133 Reply Likes
Mike,

Try:

Set p_objSelectedTopic = ......

Nigel

P.S. And yes, Visual Studio is sooo much easier!!!.. lol
(Edited)
Photo of Mike Danielski

Mike Danielski

  • 191 Posts
  • 6 Reply Likes
Ah-ha! That did it. It has been sooooooo long since I didn't anything in VBA, I totally forgot about those assignment conventions :) You rule - thanks again!
Photo of Mike Danielski

Mike Danielski

  • 191 Posts
  • 6 Reply Likes
Nigel, you are a rock star! Thank you so much for the late night feedback - I will put it to good use right away :)