Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Create and open temporary document based on template not saved in SuperOffice

Hi,

I am trying to create a temporary document based on a template and the document should not be saved in SuperOffice. This is controlled in the administrator of the template (do not save to database).

The following script somehow works:

Dim objSO
Set objSO = CreateObject("SuperOffice.Application")

If Not (objSO is nothing) Then

objSO.CurrentDocument.ChangeIdentity 0
objSO.CurrentDocument.SetDefaults

objSO.Context.Set "superoffice:document"

objSO.CurrentDocument.Template = objSO.Database.GetListItemByName(130, "Pipeline")

End If

However, the document dialogue box shows up and you need to click "Save" in order to create and open the document.

What would be much better was that the document is just created in the users temporary folder and opened so I tried the following apporoach:

Dim objSO
Dim SoDoc

Set objSO = CreateObject("SuperOffice.Application")

If not (objSO is nothing) Then

set SoDoc = objSO.Database.CreateDocument

SoDoc.setDefaults

SoDoc.Template = objSO.Database.GetListItemByName(130, "Pipeline")

SoDoc.GenerateDocumentFile

SoDoc.Save

End If

Set ObjSO = Nothing

In this case the document is saved in SuperOffice (why?) and the document does not open?

Any help will be highly appreciated.

RE: Create and open temporary document based on template not saved in SuperOffice

Hi Peter,
In Win 8.0, we have adopted the netserver docplugin.
Though a good idea, I believe it turned out to have its issues!

I have tried a work-around (by tracing in our code) that works for me in 8.1.
Can you give it a try?

Set doc = app.Database.CreateDocument
doc.SetDefaults
doc.Template = app.Database.GetListItem( 130, 20 )
doc.GenerateDocumentFile vbFalse, "", "D:\outdoc.doc"
CreateObject("WScript.Shell").Run("D:\outdoc.doc")

20 is your doctmpl id. Can be any tmpl - need not be one that is marked as not to be saved to the db.
You may need to do some work with generating a output file path. It should not be an existing file!

Conrad

 

 

 

 

Af: Conrad Weyns 25. jun 2017

RE: Create and open temporary document based on template not saved in SuperOffice

Hi Conrad,

Thank you so much for your highly appeciated help!

I enden up with the following solution:

Dim objSO
Dim SoDoc
Dim oFile
Dim TemporaryFolder
Dim XLRun
Dim objXL
Dim objWorkBook

Const TemporaryFolderID = 2

Set oFile = CreateObject("Scripting.FileSystemObject")
TemporaryFolder = oFile.GetSpecialFolder(TemporaryFolderId) + "\"
Set XLRun = CreateObject("WScript.Shell")
Set objSO = CreateObject("SuperOffice.Application")

If Not (objSO is Nothing) Then
Set SoDoc = objSO.Database.CreateDocument
SoDoc.SetDefaults
SoDoc.Template = objSO.Database.GetListItem(130, 235)
SoDoc.GenerateDocumentFile vbFalse, "", TemporaryFolder & "PipeLine.xlsm"
End If

Set objXL = CreateObject("Excel.Application")
objXL.Application.Visible = True
XLRun.AppActivate objXL.Caption
Set objWorkBook = objXL.Workbooks.Open(TemporaryFolder & SoDoc.filename)

Set oFile = Nothing
Set XLRun = Nothing
Set objSO = Nothing
Set SoDoc = Nothing
Set objXL = Nothing
Set objWorkBook = Nothing

I use the temporary folder defined by SuperOffice (TemporaryFolder) and if the filename already exists SuperOffice will rename the file which is catched by SoDoc.filename.

Thank you again for your suggestion!

Peter

Af: Peter Munk 26. jun 2017