Macro to Save and Close All Projects

S

Sean

At my work we use Project Server 2003. When we accept updates for
projects, Project opens up each file, makes the changes, and saves
them. But when we close the files, project always wants us to save
them. It gets annoying. So I wrote a macro to go through all the
projects and close them until either they are all gone or the only one
left is 'Project1', the default. But I don't have tons of confidence
in my VB coding skills yet, and want to run this macro by some experts
and see if there are some obvious holes or oversights on my part.
Here's the code:

Sub NextSaveClose()
Dim count As Integer
Dim I As Integer
Dim J As Integer
Dim compare As Integer

count = Windows.count
I = 0

Do While Application.Windows.count > I
If Windows.ActiveWindow.Caption <> "Project1" Then
FileSave
FileClose 'should I add something here in case the file
cannot save for some reason?
Else
I = 1
J = Windows(I).Index
Windows.ActiveWindow.Visible = False 'moves to next
active window
End If
Loop

Windows(J).Visible = True 'brings back project1

End Sub

Thanks for your help!

~Sean
 
R

Rod Gill

Hi,

Firstly, this VBA group is closing soon, so please use the project.developer
group in future.

The following code should work for you:

Sub CloseProjects()
Dim Proj As Project
For Each Proj In Application.Projects
If Proj.Name <> "Project1" Then
Proj.Activate 'FileClose only works on the active project
FileClose pjDoNotSave
End If
Next Proj
End Sub

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
S

Sean

Rod,

Thanks for the code and the heads up. I'll use the project.developer
group in the future. It does what I wanted, but in a much better way.

~Sean
 

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