Using CreateObject to Access the currently loaded MS Project file 
Author Message
 Using CreateObject to Access the currently loaded MS Project file

I'm trying to access the currently loaded MS Project file
so that I can ad tasks lines.  If I use GetObject and name
the file name my code works but not if I access by class
name.  In that case it does not recognize .tasks as a
method.  Here are the code snippets, the first showing
what works and the second showing what I would like to get
working as it is more general.

Thanks for any help.

Jack

'Works but is specific to a particular MS Project File
Dim objproject, tasks
Set objproject = GetObject(,"MSProject.Application")
Set objproject = GetObject("w:\projet\admin\gestion
projets\MSProject\EquipeJack.mpp")
'Create the tasks object
Set tasks = objproject.tasks

'Trying to be general to the currently loaded MS Project
'file but generates "Property / Method not found" error
'when run the last line: Set tasks = objproject.tasks
Dim objproject, tasks
Set objproject = GetObject(,"MSProject.Application")
'Create the tasks object
Set tasks = objproject.tasks



Wed, 17 Nov 2004 01:44:20 GMT  
 Using CreateObject to Access the currently loaded MS Project file
Hi,

If the macro is running in Project try:
Activeproject.tasks.add "TaskName"

If the macro is running in Access, Excel or another program try:

Dim ProjApp as  MSProject.Application
Dim Proj as MSProject.Project

Set Projapp = GetObject(,"MSProject.Application")
Set Proj=ProjApp.ActiveProject
Proj.Tasks.Add "TaskName"

You need to set a reference to the Project app (Tools, References in the
VBE)

--

Visit www.mvps.org/project/ for the Project MVP's FAQ and third party
add-ons

Rod Gill
Microsoft Project MVP
Visit www.projectlearning.com for customized Project and Office VBA macros
and Project companion software


Quote:
> I'm trying to access the currently loaded MS Project file
> so that I can ad tasks lines.  If I use GetObject and name
> the file name my code works but not if I access by class
> name.  In that case it does not recognize .tasks as a
> method.  Here are the code snippets, the first showing
> what works and the second showing what I would like to get
> working as it is more general.

> Thanks for any help.

> Jack

> 'Works but is specific to a particular MS Project File
> Dim objproject, tasks
> Set objproject = GetObject(,"MSProject.Application")
> Set objproject = GetObject("w:\projet\admin\gestion
> projets\MSProject\EquipeJack.mpp")
> 'Create the tasks object
> Set tasks = objproject.tasks

> 'Trying to be general to the currently loaded MS Project
> 'file but generates "Property / Method not found" error
> 'when run the last line: Set tasks = objproject.tasks
> Dim objproject, tasks
> Set objproject = GetObject(,"MSProject.Application")
> 'Create the tasks object
> Set tasks = objproject.tasks



Wed, 17 Nov 2004 07:54:18 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Using MS Access to populate specific fields in MS Project

2. Using MS Access 97 to Create and Manage MS Project 98

3. Q: VB4-32: Problems to load MS Project 4.1 project via OLE

4. Using the MS Windows Browse file DLL from MS Access

5. Using the MS Windows Browse file DLL from MS Access

6. MS Project as an application createobject

7. Using MS Access to populate fields in Project - UPDATE

8. Using CreateObject in HTML file to access a VB created DLL

9. Access MS Project data via the Microsoft.Project.OLEDB.9.0 in ASP

10. Accessing MS Project files

11. Using VB to access MS Access (mdb file) in remote host

12. Driving MS Project from MS Access 2000 developed application

 

 
Powered by phpBB® Forum Software