[Solved] Filepicker to write Multiple File Names On A Column

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

[Solved] Filepicker to write Multiple File Names On A Column

Post by sokolowitzky »

Hello,

I have found a working code that can choose multiple file names. But I can not make it write these names on a column.
I have tried to define a cell address with a variable, but it gives error.

here is the main code, that works without a problem.

Code: Select all

REM  *****  BASIC  *****

Option Explicit

Sub Selectmultifiles(evt As Object)
Dim FP As Object, files() As String
Dim repCommun As String, info As String, LF As String
Dim selFile As Variant, typeFP As Variant
Dim x As Long

LF = chr(10)

  FP = CreateUnoService("com.sun.star.ui.dialogs.SystemFilePicker") 

FP.setMultiSelectionMode(True)
FP.Title = "Choose Multiple Files"
if FP.execute = com.sun.star.ui.dialogs.ExecutableDialogResults.OK then
  files() = FP.getFiles()
 
 
  On Error Resume Next
  selFile = FP.getSelectedFiles()
  On Error GoTo 0
  if IsEmpty(selFile)  then
    info = info & LF & ".SelectedFiles don't exist."
  else 
    info = info & LF &  ".SelectedFiles :" & LF
    for x = 0 to UBound(selFile)
      info = info & x & " : " & selFile(x) & LF

      
    next
  end if
  MsgBox(info, 0, "FilePicker : " )


end if
FP.dispose
End Sub
I tried adding this line in the loop.

Code: Select all

cello=thiscomponent.sheets(0).getcellbyposition(0, x) 
cello.string = selFile(x)
it says variable not defined, probably because of "x" that is used in the loop. I thought x meant a number beginning from 0 to Ubound
How should I modify this?

By the way, this code does not work in openoffice due to some bug. Instead I work it on LO 6.0
Last edited by sokolowitzky on Sun Sep 16, 2018 9:17 am, edited 1 time in total.
Win10-OpenOffice 4.1/LibreOffice 7.4
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Filepicker to write Multiple File Names On A Column

Post by RoryOF »

You use Option Explicit, but have not defined cello
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

Re: Filepicker to write Multiple File Names On A Column

Post by sokolowitzky »

Yes. That worked. Thanks a million times.

So here is the code for the ones somehow might need a solution in next times and find this topic.

Code: Select all

REM  *****  BASIC  *****

Option Explicit

Sub Selectmultifiles(evt As Object)
Dim FP As Object, files() As String
Dim repCommun As String, info As String, LF As String
Dim selFile As Variant, typeFP As Variant
Dim x As Long
Dim y As string
Dim cello as object

LF = chr(10)

  FP = CreateUnoService("com.sun.star.ui.dialogs.SystemFilePicker") 

FP.setMultiSelectionMode(True)
FP.Title = "Choisissez plusieurs fichiers"
if FP.execute = com.sun.star.ui.dialogs.ExecutableDialogResults.OK then
  files() = FP.getFiles()
 
 
  On Error Resume Next
  selFile = FP.getSelectedFiles()
  On Error GoTo 0
  if IsEmpty(selFile)  then
    info = info & LF & ".SelectedFiles don't exist."
  else 
    info = info & LF &  ".SelectedFiles :" & LF
    for x = 0 to UBound(selFile)
      info = info & x+1 & " : " & selFile(x) & LF
cello=thiscomponent.sheets(0).getcellbyposition(0, x) 
cello.string = selFile(x)
      
    next
  end if
  MsgBox(info, 0, "FilePicker : " )
msgbox x

end if
FP.dispose
End Sub
Win10-OpenOffice 4.1/LibreOffice 7.4
Post Reply