Selecting tags with VBA

For Each f In clickData.func.sourcetab.selected For Each tag In f.metadata.tags If (tagString <> "") Then tagString = tagString & "; " tagString = tagString & tag Else tagString = tag End If Next Next

This code snippet selects all the tags in an image and pops them into a variable separated by semi-colons. It is great as far as it goes, but has one major drawback.

If the user inadvertently selects more than one file the variable ends up with tags from multiple files. I have been banging my head against the wall trying to work out how I can make the code work on only the first file selected.

Any help from you VBA gurus would be most welcome.

1 Like


Function OnClick(ByRef clickData) Dim f If clickData.func.sourcetab.selected_files.count = 0 Then DOpus.Output "Nothing is selected" Else Set f = clickData.func.sourcetab.selected_files(0) DOpus.Output "First selected file: " & f End If End Function

Whenever you see "for each" that means, "for ALL".

For Each f In clickData.func.sourcetab.selected

This iterates over each file in the collection. Leo's snippet references the first file - selected_files(0) - directly.

Many thanks, Leo