'VBA Excel couldn't find custom values from MS Project

I've been trying to find Text1 from MS Project using Excel VBA .Find method but it doesn't seem to be working. I have a working code but it is very slow because it loops through every task. Here is my code:

Sub Exp()
    With Application.FileDialog(msoFileDialogOpen)
    .Filters.Clear
    .Filters.Add "MPD", "*.mpp*"
       If .Show = True Then
          Dim getfilename As String
          Dim appProj As MSProject.Application
          Dim Found As Boolean
          Dim TaskObject As Object
          getfilename = .SelectedItems(1)
          Set appProj = CreateObject("Msproject.Application")
             appProj.FileOpen (getfilename)
             appProj.Visible = True
          Found = appProj.Find (Field:="Text1", Test:="equals", Value:="Exp1")
          If Found Then
             Set TaskObject = appProj.ActiveCell.Task
             Debug.Print TaskObject.UniqueID & " - " & TaskObject.Name
          Else
             MsgBox "Not Found"
          End If
       End If
    End With
   End Sub

How can i get this code working or is there another way of doing this? Thanks for your answers.



Solution 1:[1]

Find is a method of the Application object, not the Project object. So the correct way to use it is this:

Found = Application.Find(Field:="UniqueID", Test:="equals", Value:="130")

However, there is a faster way to get a reference to a task object by way of its UniqueID by using the UniqueID property of the Tasks object:

Set TaskObject = ActiveProject.Tasks.UniqueID(130)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rachel Hettinger