Save individual Projects from within a master

B

Brian Lukanic

I asked this in the Server forum, however I think that what I really want is
to create a custom button in VBA.

I have a master project with four subprojects. I want to select the summary
line of an individual project in that master, and push a button that
saves/publishes/checks in the individual project.

Can someone provide me the syntax that would essentially
"save/publish/check-in currently selected project?"
 
R

Rod Gill

Try recording a macro (tools, Macro, Record Macro) and see what gets
recorded as your starting point. If that doesn't help, let us know.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
B

Brian Lukanic

Rod,

I believe my best chance is to leverage the fact that the value in the Name
column in the selected line to save also is the filename. So by getting that
name and declaring it as an object variable, I should then be able to save &
publish, correct?

The below code is close, however I am not sure how to use the variable as an
Object without getting a with block error. I'm also unsure of the exact save
& publish command but I can probably figure that out. Here's my code:

Sub SelectedTasks()

Dim T As Task
Dim MyFileName As Object

If (ActiveSelection.Tasks Is Nothing) Then
MsgBox "You did not select a SubProject!"
End If

If Not (ActiveSelection.Tasks Is Nothing) Then
For Each T In ActiveSelection.Tasks
' Test for blank task row
If Not (T Is Nothing) Then
MyFileName = ActiveSelection.Tasks
MsgBox MyFileName & " is about to get saved/Published"
pj.Application.FileSave MyFileName
'Command to publish will go here
End If
Next T
End If

End Sub
 
R

Rod Gill

To only save and publish the selected Sub-Project you will have to open it
first, then save and publish. Otherwise the consolidated project is saved
and published. Again, recording you doing this will give you most of the
code, including how to publish.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
B

Brian Lukanic

I've gotten it to work based on your recommendation. I guess I had been hung
up on the concept of opening the project essentially a second time (already
open in the master) to be able to save it.

Even though it appears to open the project a second time and includes any
project-level changes I made via the master, I would feel safer to FIRST save
the edited project, and THEN open it that second time before publishing.
Again, it does not seem to cause a problem if I don't, but I put a save
command at the front of the loop just to be safe. My concern is that the
changes made via the master would not shot up in the re-opened project if it
has not first been saved.

Anyway - the code below does exactly what I want. It will open/publish/close
all selected subprojects in the master.

Rod, is there a way to "save all open projects" seamlessly via VBA so that I
can eliminate the manual interaction required by the user in lines 4-6?




Sub PublishSelectedSubprojects()

Dim T As Task
Dim MyFileName As String


MsgBox "In the next window, please choose Save All."
FileSave
MsgBox "Done saving. Now I will Publish each selected Project."

For Each T In ActiveSelection.Tasks
If Not (T Is Nothing) Then
MyFileName = "<>\" & T.Name
MsgBox T.Name & " is about to get published."
FileOpenEx Name:=MyFileName, ReadOnly:="False"
FileSave
DisplayAlerts = False
ScreenUpdating = False
publish Republish = True, WssURL = False
FileClose
ScreenUpdating = True
DisplayAlerts = True
End If
Next T

End Sub
 

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