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

Creating a macro - Writing a Script - Using the API

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

Postby sokolowitzky » Sun Sep 16, 2018 8:52 am

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   Expand viewCollapse view
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   Expand viewCollapse view
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.
Ocasionally; Windows 10 & Open Office 4.1.3//LibreOffice 6.0
sokolowitzky
 
Posts: 29
Joined: Mon Sep 15, 2014 7:34 pm

Re: Filepicker to write Multiple File Names On A Column

Postby RoryOF » Sun Sep 16, 2018 9:08 am

You use Option Explicit, but have not defined cello
Apache OpenOffice 4.1.5 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 27182
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Filepicker to write Multiple File Names On A Column

Postby sokolowitzky » Sun Sep 16, 2018 9:10 am

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   Expand viewCollapse view
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
Ocasionally; Windows 10 & Open Office 4.1.3//LibreOffice 6.0
sokolowitzky
 
Posts: 29
Joined: Mon Sep 15, 2014 7:34 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests