excel - How to open a save file dialogue box and save the file by writing a string into it in libreoffice.Below code is in VBA -
i following error when run below vba code in libreoffice
basic runtime error.
'423'
getsaveasfilename
' comment code starts here sub buildyaml() dim yaml string yaml = "hello world" dim vfile variant 'opening save box vfile = application.getsaveasfilename(initialfilename:=sheets("simple").cells(2, 2) & "_config.yaml", _ filefilter:="yaml config file (*.yaml), *.xlsb, files (*.*), *.*", _ title:="save config file as:") if vfile <> false call savefile(vfile, yaml) msgbox ("file saved") end if end sub
saving file
sub savefile(filename variant, content string) dim fso object set fso = createobject("scripting.filesystemobject") dim ofile object set ofile = fso.createtextfile(filename) ofile.writeline content ofile.close set fso = nothing set ofile = nothing end sub
this should libreoffice calc equivalent vba macro.
sub buildyaml() dim yaml string yaml = "hello world" dim adialogtyp(0) adialogtyp(0) = com.sun.star.ui.dialogs.templatedescription.filesave_autoextension odialog=createunoservice("com.sun.star.ui.dialogs.filepicker") odialog.initialize(adialogtyp()) odialog.appendfilter("yaml config file (*.yaml)","*.yaml") odialog.appendfilter("all files (*.*)","*.*") odialog.settitle("save config file as:") odialog.execute if ubound(odialog.files) < 0 sfilename ="" else sfilename=odialog.files(0) end if sfiltername=odialog.currentfilter if sfilename <> "" call savefile(sfilename, yaml) msgbox "file saved" end if end sub sub savefile(sfilename string, scontent string) osimplefileaccess = createunoservice ("com.sun.star.ucb.simplefileaccess") ooutputstream = createunoservice ("com.sun.star.io.textoutputstream") ooutputstream.setoutputstream(osimplefileaccess.openfilewrite(sfilename)) ooutputstream.writestring(scontent) end sub
save file fixed file name in path calc document stored:
sub buildyaml2() dim yaml string yaml = "hello world" globalscope.basiclibraries.loadlibrary("tools") spath=directorynameoutofpath(thiscomponent.geturl(), "/") sfilename = "test.yaml" call savefile(spath & "/" & sfilename, yaml) msgbox "file saved" end sub
greetings
axel
Comments
Post a Comment