I’m having some trouble getting the FilePicker service created in save mode to work.
.
I tried some constants from the com.sun.star.ui.dialogs.TemplateDescription object, but to no success.
.
Any help would be appreciated.
.
=========== CODE SNIPPET ===========
Option Compatible ' Permite utilizar elementos adicionais na linguagem
Option Explicit ' Força a declaração de variáveis
REM -----------------------------------------------------------------------------
'''
' Cria copia de backup do arquivo em PDF
'''
Sub GuardarCopiaPDF()
Dim oForm As Object ' Formulário onde ancorados controles
Dim oTxtOficio As Object ' Caixa de texto Oficio
Dim oLstBox As Object ' Caixa de lista asunto
Dim oFileDialog As Object ' com.sun.star.ui.dialogs.FilePicker (Explorador de arquivos)
Dim sFileName As String ' Nome do arquivo
Dim s As String ' Variável de texto auxiliar
REM Obtem Formulário da paǵina de desenho
oForm = ThisComponent.DrawPage.Forms.getByName("Formulário")
oTxtOficio = oForm.getByName("txtOficio")
REM Obtem assunto na caixa de lista
oLstBox = oForm.getByName("lstAssunto")
oLstBox = ThisComponent.CurrentController.getControl(oLstBox)
s = Left(oLstBox.SelectedItem, Len(oLstBox.SelectedItem) -1)
REM Constroi nome do arquivo
sFileName = "Oficio_" & oTxtOficio.Text & "_" & Year(Now) & "_RI_" & s & ".pdf"
REM Constroi caminho para diretorio padrao
s = ConvertToUrl( CurDir() & GetPathSeparator() & "PDF" )
REM Instancia explorador no modo salvar
REM Ajuda: https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1ui_1_1dialogs_1_1TemplateDescription.html
oFileDialog = com.sun.star.ui.dialogs.FilePicker.createWithMode(10) ' FILESAVE_AUTOEXTENSION
With oFileDialog
.setTitle("Salvar")
.appendFilter( "PDF - Portable Document Format (.pdf)", "*.pdf" )
.setDisplayDirectory( s )
.setDefaultName(sFileName)
If .Execute() <> 1 Then Exit Sub
End With
End Sub ' BasicProject.BP_Interacao.GuardarCopiaPDF
=========== SAMPLE ===========
Oficio_000_ANO_RI_assunto.odt (53,3,KB)
.
.
=========== ANSWER FOR THE CODE (by @elmau )===========
REM Instancia explorador no modo salvar
REM Ajuda: https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1ui_1_1dialogs_1_1TemplateDescription.html
oFileDialog = com.sun.star.ui.dialogs.FilePicker.createWithMode(10) ' FILESAVE_AUTOEXTENSION
With oFileDialog
.setTitle("Salvar")
.appendFilter( "PDF - Portable Document Format (.pdf)", "*.pdf" )
.setDisplayDirectory( s )
.setDefaultName(sFileName)
If .Execute() <> 1 Then Exit Sub
sUrl = .SelectedFiles(0)
End With
REM Filtro de exportação
REM Ajuda: https://help.libreoffice.org/latest/pt-BR/text/shared/guide/convertfilters.html?DbPAR=SHARED#bm_000
filterProps(0).Name = "FilterName"
filterProps(0).Value = "writer_pdf_Export"
REM Salva o arquivo
If Not FileExists( sUrl ) Then
ThisComponent.storeToURL(sUrl, filterProps() )
End If