Ask Your Question
0

Code to close doc without saving in Writer

asked 2020-08-03 23:08:18 +0200

I would like code for a macro doc current without saving in Writer.

I would also like code for macros to:

  • close all opened documents saving
  • close all opened documents without saving
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2020-08-04 19:28:32 +0200

JohnSUN gravatar image

It can be something like this:

Sub CloseAllDocs(Optional SaveBeforeClose As Boolean, Optional sType As String)
Rem If SaveBeforeClose AND document was modified AND can be stored then it will be stored
Rem sType can be "swriter",  "scalc", "simpress,sdraw", etc.
Dim oComponents As Object
Dim oComponent As Object
Dim sComponentType As String 
Rem Default values: text documents only 
    If IsMissing(sType) Then sType = "swriter"
Rem ...and close without saving
    If IsMissing(SaveBeforeClose) Then SaveBeforeClose = False
    GlobalScope.BasicLibraries.loadLibrary( "Tools" )
    oComponents = StarDesktop.Components.CreateEnumeration
    While oComponents.HasmoreElements
        oComponent = oComponents.NextElement
        If hasUnoInterfaces(oComponent,"com.sun.star.frame.XModel") Then 
            sComponentType = GetDocumentType(oComponent)
            If InStr(sType, sComponentType) > 0 Then 
                If SaveBeforeClose Then
                    If (oComponent.isModified) Then
                        If (oComponent.hasLocation AND (Not oComponent.isReadOnly)) Then 
                            oComponent.store()
                        End If
                    End If
                End If
                oComponent.setModified(False)
                DisposeDocument(oComponent)
            End If
        End If
    Wend
End Sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-08-03 23:08:18 +0200

Seen: 18 times

Last updated: Aug 04