Thank you for your tips. A compiled add-in makes a lot more sense. After
(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
"Carlos J. Quintero [MVP]" <carlosq@NOSPAMsogecable.com> wrote in message
news:%230DVRDcMEHA.644@tk2msftngp13.phx.gbl...
> 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.
>
> --
>
> 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)
>
>
>
> "Andrew Hilton" <hiltona@ocean.com.au> escribió en el mensaje
> news:OPLWh9mLEHA.3892@TK2MSFTNGP11.phx.gbl...
> > Hello,
> >
> > We have a lot of files in different directories in our project. I wrote
a
> > macro to find and open a source file based on the filename rather than
> using
> > the solution explorer. But it's so slow as to be unusable. Is there
> > something obvious in my code, or is there another way to do this?
> >
> > Andrew
> >
> > Public Sub FindFile()
> >
> > Dim ps As ProjectItems =
> > ActiveDocument.ProjectItem.ContainingProject.ProjectItems
> >
> > Dim s As String = InputBox("Enter part of the filename to open.",
> "Open
> > File")
> >
> > Dim re As New Regex(s, RegexOptions.IgnoreCase)
> >
> > If s = "" Then Exit Sub
> >
> > If Not IterateProjectItems(ps, re, s) Then MsgBox("No matching files
> > found")
> >
> > End Sub
> >
> >
> >
> > Private Function IterateProjectItems(ByRef ps As ProjectItems, ByRef re
As
> > Regex, ByVal s As String)
> >
> > Dim pi As ProjectItem
> >
> > Dim found As Boolean
> >
> > For Each pi In ps
> >
> > If re.IsMatch(pi.Name) Then
> >
> > found = True
> >
> > pi.Open()
> >
> > pi.Document.Activate()
> >
> > End If
> >
> > found = IterateProjectItems(pi.ProjectItems, re, s) Or found
> >
> > Next
> >
> > IterateProjectItems = found
> >
> > End Function
> >
> >
>
>