OpenOffice.orgメモ
OpenOffice.orgで開いている表計算シートの全タブをCSVで保存するマクロ改。
デフォルトでカレントディレクトリを選択するように変更&選択ダイアログを「キャンセル」すると
ちゃんとキャンセルされるように設定。
Sub Main End Sub Sub Macro1 End Sub Sub SaveAllSheetAsCSV Dim oDoc As Object oDoc = ThisComponent Dim oCController as object oCController = oDoc.CurrentController If oDoc.supportsService( “com.sun.star.sheet.SpreadsheetDocument” ) Then ‘ MsgBox “Supported” ‘ MsgBox oDoc.URL Dim oSheets As Object oSheets = oDoc.getSheets() Dim oFolderPicker As Object oFolderPicker = createUnoService(“com.sun.star.ui.dialogs.FolderPicker”) oFolderPicker.setDisplayDirectory(oDoc.URL) if oFolderPicker.execute() = 0 Then Exit Sub End If ‘ MsgBox oFolderPicker.getDirectory() Dim aArgs(1) As New com.sun.star.beans.PropertyValue aArgs(0).Name = “FilterName” aArgs(0).Value = “Text – txt – csv (StarCalc)” aArgs(1).Name = “FilterOptions” aArgs(1).Value = “44,34,76” Dim SaveDir As String SaveDir = oFolderPicker.getDirectory() For i% = 0 To oSheets.getCount() – 1 Dim SaveURL As String SaveURL = SaveDir + “/” + oSheets.getByIndex( i ).getName() + “.csv” oCController.ActiveSheet = oSheets.getByIndex( i ) MsgBox SaveURL oDoc.storeAsURL( ConvertToURL(SaveURL), aArgs() ) Next i oCController.ActiveSheet = oSheets.getByIndex( 0 ) Else MsgBox “Document is not a spreadsheet.” End If End SubREM ***** BASIC *****