Can not check in a project with VBA

S

Steve Chermak

I am new at Project Server 2007.

We have an Excel macro that is designed to run overnight to launch Project
VBA code in order to update projects in the Project Server. These projects
were created in Project Web Access.

Right now the code is just prototype to try and get this working.

The VBA code will not properly check in the project, the project appears on
the force check in list in PWA afterwards.

We have gotten code going that will check in and out documents in a document
library, but we can not get this going and when we try and identify the error
codes they don't provide much help.

Below is the code. Test code put in indicates that the project can not be
checked out, let alone in, yet we don't know why. If anybody can help we
would appreciate it.

Thanks, Steve Chermak

========

Dim pjApp As Object, pjProj As MSProject.Project, pjApp2 As
MSProject.Application
Dim pjProjs As MSProject.Projects


Dim pjProjectName As String
Dim pjProjectFullName As String

Sub Execute_Open()

Application.WindowState = xlMinimized


If OpenProjectServer() = False Then
MsgBox "Error: Could NOT Open MSProject From Project Server!"
End
End If

Set pjApp2 = pjApp

pjApp2.FileOpenEx Name:="<>\VPMI SFU 2010 - MH CONSTRUCTION",
ReadOnly:=False

pjApp2.DisplayAlerts = False

pjApp2.WindowState = pjMaximized

Set pjProjs = pjApp2.Projects
Set pjProj = pjApp2.ActiveProject

MsgBox (pjProjs.Count)
MsgBox (pjProjs.Item(1).Name)

pjProjectFullName = pjProj.FullName
pjProjectName = pjProj.Name

Dim CanIt As Boolean
pjProjs.Item(1).Activate

CanIt = pjProjs.CanCheckOut(pjProjs.Item(1))

MsgBox (CanIt)

If pjProjs.CanCheckOut(pjProjs.Item(1)) Then
pjProjs.CheckOut (pjProjs.Item(1))

Else
MsgBox ("not checked out - error: " & Err.Number)

End If

pjProj.Tasks(2).Cost = 111


If pjProj.CanCheckIn = True Then
pjProj.CheckIn

Else
MsgBox ("not checked in " & Err.Number)
End If


pjApp2.FileCloseEx pjSave
pjApp.DisplayAlerts = True
pjApp2.WindowState = pjMinimized

Set pjProj = Nothing
Set pjApp2 = Nothing

Set pjWkbk = Nothing
Set pjApp = Nothing

Application.WindowState = xlNormal

End Sub


Function OpenProjectServer()

tStart = Timer
Set pjApp = Nothing

On Error Resume Next
Shell "C:\Program Files\Microsoft Office\Office12\WINPROJ.EXE /s
""http://vpmiweb1/PWA"""
Do While pjApp Is Nothing And Timer < (tStart + 30)
Set pjApp = GetObject(, "MSProject.Application")
Loop

If Not pjApp Is Nothing Then
OpenProjectServer = True
Else
OpenProjectServer = False
End If

End Function
 
R

Ray McCoppin

I would use "FileCloseEx([Save As PjSaveType = pjPromptSave], [NoAuto],
[CheckIn]) As Boolean"

And set the Checkin Parameter to True.


Hope this helps

--
Ray McCoppin

http://www.randsmanagement.com
Project Server 2007 Automation Tools
Project Server 2007 Archive Tool
SRS gantt charts
 
B

Ben Howard

Hi Steve, presumably you want to publish all the projects so that the cube is
upto date etc. I've a product that I resell to do this, it is server based
and it'll only publish projects that have changes. Let me know if you are
interested.
--
Thanks, Ben.

Please rate this post if it helped.
http://appleparkltd.spaces.live.com/
 
S

Steve Chermak

Ray,

I tried this out and it seems to have solved the problem, at least with my
first tests. We will test it out further.

Thanks for the suggestion and help.
Steve

Ray McCoppin said:
I would use "FileCloseEx([Save As PjSaveType = pjPromptSave], [NoAuto],
[CheckIn]) As Boolean"

And set the Checkin Parameter to True.


Hope this helps

--
Ray McCoppin

http://www.randsmanagement.com
Project Server 2007 Automation Tools
Project Server 2007 Archive Tool
SRS gantt charts


Steve Chermak said:
I am new at Project Server 2007.

We have an Excel macro that is designed to run overnight to launch Project
VBA code in order to update projects in the Project Server. These projects
were created in Project Web Access.

Right now the code is just prototype to try and get this working.

The VBA code will not properly check in the project, the project appears on
the force check in list in PWA afterwards.

We have gotten code going that will check in and out documents in a document
library, but we can not get this going and when we try and identify the error
codes they don't provide much help.

Below is the code. Test code put in indicates that the project can not be
checked out, let alone in, yet we don't know why. If anybody can help we
would appreciate it.

Thanks, Steve Chermak

========

Dim pjApp As Object, pjProj As MSProject.Project, pjApp2 As
MSProject.Application
Dim pjProjs As MSProject.Projects


Dim pjProjectName As String
Dim pjProjectFullName As String

Sub Execute_Open()

Application.WindowState = xlMinimized


If OpenProjectServer() = False Then
MsgBox "Error: Could NOT Open MSProject From Project Server!"
End
End If

Set pjApp2 = pjApp

pjApp2.FileOpenEx Name:="<>\VPMI SFU 2010 - MH CONSTRUCTION",
ReadOnly:=False

pjApp2.DisplayAlerts = False

pjApp2.WindowState = pjMaximized

Set pjProjs = pjApp2.Projects
Set pjProj = pjApp2.ActiveProject

MsgBox (pjProjs.Count)
MsgBox (pjProjs.Item(1).Name)

pjProjectFullName = pjProj.FullName
pjProjectName = pjProj.Name

Dim CanIt As Boolean
pjProjs.Item(1).Activate

CanIt = pjProjs.CanCheckOut(pjProjs.Item(1))

MsgBox (CanIt)

If pjProjs.CanCheckOut(pjProjs.Item(1)) Then
pjProjs.CheckOut (pjProjs.Item(1))

Else
MsgBox ("not checked out - error: " & Err.Number)

End If

pjProj.Tasks(2).Cost = 111


If pjProj.CanCheckIn = True Then
pjProj.CheckIn

Else
MsgBox ("not checked in " & Err.Number)
End If


pjApp2.FileCloseEx pjSave
pjApp.DisplayAlerts = True
pjApp2.WindowState = pjMinimized

Set pjProj = Nothing
Set pjApp2 = Nothing

Set pjWkbk = Nothing
Set pjApp = Nothing

Application.WindowState = xlNormal

End Sub


Function OpenProjectServer()

tStart = Timer
Set pjApp = Nothing

On Error Resume Next
Shell "C:\Program Files\Microsoft Office\Office12\WINPROJ.EXE /s
""http://vpmiweb1/PWA"""
Do While pjApp Is Nothing And Timer < (tStart + 30)
Set pjApp = GetObject(, "MSProject.Application")
Loop

If Not pjApp Is Nothing Then
OpenProjectServer = True
Else
OpenProjectServer = False
End If

End Function
 
R

Ray McCoppin

Steve, Can you tell us what you trying to do with the VBA code. It is now
possible to doing things on the server via the PSI. VBA is not very stable
at doing this kind of thing and server side code would be much more stable.

Also in your code the FileOpenEx with ReadOnly set to False will make the
Project Checked Out to you.

Hope this helps
--
Ray McCoppin

http://www.randsmanagement.com
Project Server 2007 Automation Tools
Project Server 2007 Archive Tool
SRS gantt charts
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top