VBA Excel 无法从 MS Project 找到自定义值
我一直在尝试使用 Excel VBA .Find 方法从 MS Project 查找 Text1,但它似乎不起作用。我有一个工作代码,但它非常慢,因为它循环执行每个任务。这是我的代码:
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
我怎样才能让这个代码工作或者有其他方法可以做到这一点? 感谢您的回答。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查找是应用对象的一种方法,不是项目对象。因此,正确使用它的方法是:
但是,有一种更快的方法可以通过使用 uniqueId 任务对象的属性:
Find is a method of the Application object, not the Project object. So the correct way to use it is this:
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: