Code to close doc without saving in Writer

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

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,"") 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 
						End If
					End If
				End If
			End If
		End If
End Sub