Page 1 of 1

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

Posted: Sun Sep 16, 2018 8:52 am
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

Re: Filepicker to write Multiple File Names On A Column

Posted: Sun Sep 16, 2018 9:08 am
by RoryOF
You use Option Explicit, but have not defined cello

Re: Filepicker to write Multiple File Names On A Column

Posted: Sun Sep 16, 2018 9:10 am
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