none
Save before/after print RRS feed

  • Question

  • Microsoft Word 2013 - Is it possible to save a document read only in a specific location only if it has been printed?

    I have been trying to intercept the Print Event but as I have no programming experience I have not been able to make it work.

    If possible I would either like the document to be saved before it is printed, or if the document has been printed make it so the file cannot be closed until it is saved.

    Friday, May 12, 2017 10:20 AM

All replies

  • Hi KevinW88,

    Since this forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tool, and your issue is more related to word for developer, I will move this thread to the more related forum.

    Thanks for your understanding and support.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 15, 2017 9:13 AM
  • Hi KevinW88,

    please try to refer suggestions below.

    -> Microsoft Word 2013 - Is it possible to save a document read only in a specific location only if it has been printed?

    there is no method and property to check whether document is printed or not.

    so here as an work around we can try to use "DocumentBeforePrint" event.

    this event get execute before printing the document.

    so at this stage we can one bookmark in the document that will work as a flag and we can check this bookmark later to know whether document is printed or not.

    below is an example of that.

    Option Explicit
    
    Public WithEvents oApp As Word.Application
    
    Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
        ActiveDocument.Bookmarks("DocWasPrinted").Delete
        With ActiveDocument.Bookmarks
            .Add Range:=Selection.Range, Name:="DocWasPrinted"
            .DefaultSorting = wdSortByName
            .ShowHidden = True
        End With
    End Sub


    Option Explicit
    
    Dim oAppClass As New Class1
    
    Public Sub AutoExec()
        Set oAppClass.oApp = Word.Application
    End Sub
    
    Sub Testing()
        If hasPrinted = True Then
            MsgBox "Document was printed"
            '~~> Call your code
        Else
            MsgBox "Please Print Before Adding"
        End If
    End Sub
    
    Function hasPrinted() As Boolean
        If ActiveDocument.Bookmarks.Exists("DocWasPrinted") = True Then
            hasPrinted = True
        End If
    End Function


    Private Sub Document_Close()
         ActiveDocument.Bookmarks("DoWasPrinted").Delete
    End Sub

    Reference:

    how to check if word document has printed already

    so after checking the document is printed or not you can save the document as Read Only at particular location.

      ActiveDocument.SaveAs2 FileName:="Text.rtf", _ 
            FileFormat:=wdFormatRTF 

    Reference:

    Document.SaveAs2 Method (Word)

    other thing you had mentioned that,"If possible I would either like the document to be saved before it is printed, or if the document has been printed make it so the file cannot be closed until it is saved."

    you can save the document using Before print event as mentioned before. so it will always save the document before print.

    you just need to try to understand the example above and modify it as per your requirement.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, May 16, 2017 1:01 AM
    Moderator
  • Hi KevinW88,

    is your issue is solved?

    I can see that you did not responded to this thread after creating this thread.

    if you issue is solved then try to update the status of this thread and post your solution and mark it as an answer.

    if your issue is still exist then try to refer the suggestion given by me. it can solve your issue.

    if you have any further questions then let me know about that.

    I will try to provide you further suggestions to solve the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 28, 2017 9:35 AM
    Moderator