I've never written any Visual Studio macros, but this may be what you are looking for.
projectName = DTE.Solution.SolutionBuild.StartupProjects(0)
For Each project In DTE.Solution.Projects
If (project.ConfigurationManager IsNot Nothing) Then
' It's a project!
If (project.UniqueName = projectName) Then Return project
Else
If (project.ProjectItems IsNot Nothing) Then
For Each projectItem In project.ProjectItems
If (projectItem.SubProject IsNot Nothing) Then
' TODO: Recurse on projectItem.SubProject
End If
Next
End If
End If
Next
I left a 'TODO in there, because you would need to actually pull this out into a function that you could recursively call if you are looking to deal with nested (sub) projects.
I got this solution from this link, and while it's Visual Studio 2005-era material, it might get you going in the right direction.