Share via

Disable Save on Close

Anonymous
2015-05-08T18:56:05+00:00

Hello and thank you for your help.

I have a macro-heavy MS Project document that pulls its information from an external source. To avoid all of the details, I can solve all of my issues with one further change in VBA. I need to ensure that the document does not save on closing.

Since this project document will be used by a large number of people, I need to ensure that the user is never prompted to save after a macro is run in the project_BeforeClose private subroutine of MicrosoftProjectObjects.

This seems like it should be a very simple question, but I have not been able to find a solution. In excel, the answer is simply:

ThisWorkbook.Close SaveChanges:=True

In Word (though I have never used it), I read you can enter the MicrosoftWordObjects,

Me.Saved = True

For Project, I could not find a way to do this. There is the FileCloseEx, which hast the optional argument pjDoNotSave. Thus the line of code would be:

FileCloseEx pjDoNotSave

While this line of code works if it is contained in its own subroutine and is triggered directly, I cannot use it to remove the Save on Close prompt if the user clicks the Close button in the upper right-hand corner of the screen. If I run FileCloseEx under the project_BeforeClose event, it throws an error:

“Run-time error ‘438’: Object doesn’t support this property or method”

This is probably to avoid infinite recursion. Interestingly, if I place FileCloseEx in the Auto_Close Subroutine located in a module, it does actually undergo a single recursion and throws the same error on the second pass through. Regardless, it appears to me that the scope of FileCloseEx pjDoNotSave completes and is thrown off the stack before the actual closing of the file begins, and as a result, the window still prompts me to save before closing the file.

So my question remains, for MS project, how do you disable the save-on-close dialogue box?

PS: I would not object to disabling saving altogether on this document. In the project_BeforeSave event for other Microsoft programs, such as Excel the following seems to work (I haven’t tested that but if memory serves I didn’t have any difficulties there):

Private Sub Workbook_BeforeSave(Cancel As Boolean)

Cancel = True

End Sub

However, in the case of Microsoft project, this gets the error:

Compile error: Procedure declaration does not match description of event or procedure having the same name

So I have also been unable to disable the save feature.

Any help would be much appreciated. Thank you.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2015-05-11T18:41:29+00:00

    Thank you very much for your reply, and I apologize for not following up earlier.

    For the sake of simplicity I think it is best to get this to work where there is only one event. First:

    <code>

    Private Sub project_BeforeClose(ByVal pj As Project)

    FileCloseEx pjDoNotSave

    End Sub

    </code>

    This gives me the error: Run-time error '1100': The method is not available in this situation. This seems to be true for all events, including BeforeSave.

    Alternatively, I can delete the project_BeforeClose event altogether and create in a module:

    <code>

    Sub Auto_Save()

    FileCloseEx pjDoNotSave

    End Sub

    </code>

    This then gives me the same error. While the single recursion I saw earlier is really interesting, that macro included a "synchronize" event which may add unnecessary complications to this problem.

    with an empty document using

    <code>

    Private Sub Project_BeforeSave(Cancel As Boolean)

    Cancel = True

    End Sub

    </code>

    I still get the same error: Compile error: Procedure declaration does not match description of event or procedure having the same name.

    The only argument it will accept is "ByVal XXXX As project," and that limitation is consistent with the Microsoft documentation at https://msdn.microsoft.com/en-us/library/office/ff864024(v=office.14).aspx

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-05-08T20:36:41+00:00

    Can you post all the code in the Project_BeforeSave event please? Can't say what is happening or why, other than only VBA code can make the file save automatically.

    If the save code isn't in the BeforeSave event then maybe its saving in code run earlier?

    Was this answer helpful?

    0 comments No comments