Basically your code is right expect a couple of details not related to
performance:
1) Dim ps As ProjectItems =
ActiveDocument.ProjectItem.ContainingProject.ProjectItems
This will cause exception if there is no document open.
2) pi.Open()
pi.Document.Activate()
Maybe not all ProjectIems has a Document, so this statement can fail too.
Use instead:
Dim objWindow As Window
objWindow = pi.Open()
objWindow.Visible = True
About performance, if you move the code from a macro into a compiled addin,
it should fly faster.

Signature
Carlos J. Quintero (Visual Developer - .NET MVP)
FAQs, Knowledge Base, Files, Docs, Articles, Utilities, etc. for .NET
addins:
http://groups.yahoo.com/group/vsnetaddin/ (free join)
> Hello,
>
[quoted text clipped - 48 lines]
>
> End Function
Andrew Hilton - 10 May 2004 05:13 GMT
Carlos,
Thank you for your tips. A compiled add-in makes a lot more sense. After
some thought here we realised the same thing could be achieved by opening
the project file into a xml dom and searching for the files using xpath
(although I have yet to do any xml processing using .net). That would be a
lot quicker and still achieveable within the macro environment. If I ever
get around to coding it - I will post it here. Forgot to mention we're using
vsnet 2001, maybe macro performance has improved in the latest version.
Andrew
> Basically your code is right expect a couple of details not related to
> performance:
[quoted text clipped - 72 lines]
> >
> > End Function