There are two separate questions here, 1) the question in the body of the post and 2) the title of the post.
If I want to get the original UID of a task...
This answer is straight-forward:
originalUID = t.UniqueID Mod 4194304
Is there a way to get a subproject's seed value programmatically?
Sometimes it is necessary to find the subproject task's Unique ID as it is in the Master Project. This comes up mainly when dealing with external links (e.g. the predecessor or successor to a task is in a different project).
This code populates a dictionary that contains the name of each subproject and the base master uid. Given the native task uid, this allows you to find the task in the master project by it's master task uid.
Dim SubProjects As New Scripting.Dictionary
Const MasterUidSeed = 4194304
Function GetSubProjectInfo(ByVal prj As MSProject.Project) As Scripting.Dictionary
ShowAllTasks
Dim Subs As New Scripting.Dictionary
Dim SubProj As Subproject
For Each SubProj In ActiveProject.SubProjects
Application.Find "Unique ID", "equals", SubProj.InsertedProjectSummary.UniqueID
Application.SelectCellDown
Dim UIDBase As Long
UIDBase = (Application.ActiveCell.Task.UniqueID \ MasterUidSeed) * MasterUidSeed
Subs.Add SubProj.SourceProject.Name, UIDBase
Next
Set GetSubProjectInfo = Subs
End Function
Sub ShowAllTasks()
' expands all tasks to make sure all collapsed subprojects are loaded; presumes a task view is active
With Application
.SummaryTasksShow (True)
.FilterClear
.SelectAll
.OutlineShowAllTasks
.SelectBeginning
End With
End Sub
See this SO post for how to use Dictionaries in VBA.
More information about how master project task uids work and why using the subproject Index can lead to unexpected results:
Unique IDs within a master project
When tasks are added to a project, an incremental Unique ID is assigned, starting with 1. When projects are combined within a master project, the Unique IDs are changed by adding a seed value so that there are no duplicates within the master project.
The seed value is based on an internal, subproject "index". The first subproject's tasks are given a seed value of 4194304, the second subproject's tasks have a seed value of 8388608 (4194304 * 2), and so forth. This "index" is different from the Index property of the subproject which refers to the current position of the subrproject within the master.
If a subproject is removed from the master, it's "index" is not re-used. Similarly, if subprojects are rearranged in the master, the "index" values do not change. Therefore, you cannot use the Index property of the subproject object to obtain the internal "index" value that is used to create the seed as that property simply indicates the order of subprojects.