Create folders from cell values

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
meha
Posts: 1
Joined: Sun Aug 20, 2017 4:21 pm

Create folders from cell values

Post by meha »

I'd like to create folders from a list of cell values but I have no idea how.
Can anyone help?
OpenOffice 4.1.3 on Windows 10
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Create folders from cell values

Post by JohnSUN-Pensioner »

Welcome to forum!
Which of the parts of this task be difficult - reading strings from the cells, or creating folders?

Code: Select all

Sub crtFldrByCellVals
Dim oDataArray As Variant
Dim oData As Variant
Dim sBaseDir As String 
Dim sTrgtDir As String 
Dim i As Long 
	GlobalScope.BasicLibraries.LoadLibrary("Tools")	
	sBaseDir = ThisComponent.getURL()
	If sBaseDir <> "" Then sBaseDir = DirectoryNameOutOfPath(sBaseDir, "/")
Rem Get data from selected cells
	oDataArray = ThisComponent.getCurrentSelection().getDataArray()
	For i = LBound(oDataArray) To UBound(oDataArray)
		oData = oDataArray(i)
Rem ... and create folder for each of them		
		sTrgtDir = ConvertToURL(sBaseDir & "/" & Trim(oData(0)))
		If Dir(sTrgtDir, 16)="" Then MkDir(sTrgtDir)
	Next i
End Sub
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
Post Reply