Thursday, December 15, 2011

Tags (unknown member) : Invalid request

I received the error, "Tags (unknown member) : Invalid request.  ", within a PowerPoint add-in on the following line of code.

string tagName = Globals.ThisAddIn.Application.ActiveWindow.Selection.SlideRange.Tags.Name(i);

This line of code was in a for loop after getting the Tag.Count  and looping through the tags to find out if the tag already exists.

I then checked the available Tag Object Members.



.Name did exist.
I decided to try .Item instead to see if that would work but I could not find .Item on as a Member.


I then decided refactor my code to the following instead.

string tagValue = Globals.ThisAddIn.Application.ActiveWindow.Selection.SlideRange.Tags[tagName];

If the "tagValue" is an empty string then the Tag does not exist. 

If the tag does exist and the value is an empty string, I’m not too concerned as in my instance I will treat it as a tag that does not exist and overwrite the value of the tag.