Import calc row to csv new line with comma delimiters

asked 2019-11-05 13:20:40 +0100

ChuckyCZ gravatar image

updated 2019-11-06 15:51:39 +0100

I am not programer but I can copy paste some macro from here and from stackoverflow but little bit not understand programing language. I have formr calc file where one line is changing once execute macro and I need to add this row with cooma separators to new line in csv file via macro

I already have this macro and I have multiple form files but if users execute this macro in same time one file show error of writing to this csv file. Can you help me to solve it?

Macro:

Sub SaveCSV
Dim oDocA As Object, oDocB As Object, oSheetA As Object, Dummy(), oRangeA as object, targetcell as object
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDocA = ThisComponent
oFrameA = oDocA.CurrentController.Frame
oSheetA = oDocA.getSheets.getByIndex(7)
oRangeA = oSheetA.getCellRangeByName("C3:P3")
oDocA.CurrentController.Select(oRangeA)
oDispatcher.executeDispatch(oFrameA, ".uno:Copy", "", 0, Dummy())
oDocB = StarDesktop.loadComponentFromURL ("file:///C:/TEMP/Summary.csv", "_blank",0, Dummy() )
oSheetB = oDocB.getSheets.getByIndex(0)
c = oSheetB.createCursor
c.gotoEndOfUsedArea(false)
LastRow = c.RangeAddress.EndRow +1
targetcell= oSheetB.getCellByPosition(0,LastRow)
oDocB.CurrentController.Select(targetcell)
oFrameB = oDocB.CurrentController.Frame
oDispatcher.executeDispatch(oFrameB, ".uno:Paste", "", 0, Dummy())
oDocB.Store
oDocB.close(true)
ASheet.protect(psw)
ASheet = ThisComponent.Sheets.getByName("Formular")
ThisComponent.CurrentController.setActiveSheet(ASheet)
End Sub
edit retag flag offensive close merge delete

Comments

MACRO

 `sub Save 
Dim oDocA As Object, oDocB As Object, oSheetA As Object, Dummy(), oRangeA as object, targetcell as object oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper") oDocA = ThisComponent oFrameA = oDocA.CurrentController.Frame oSheetA = oDocA.getSheets.getByIndex(7) oRangeA = oSheetA.getCellRangeByName("C3:P3") oDocA.CurrentController.Select(oRangeA) oDispatcher.executeDispatch(oFrameA, ".uno:Copy", "", 0, Dummy()) oDocB = StarDesktop.loadComponentFromURL ("file:///C:/data.csv", "_blank",0, Dummy() ) oSheetB = oDocB.getSheets.getByIndex(0) c = oSheetB.createCursor c.gotoEndOfUsedArea(false) LastRow = c.RangeAddress.EndRow +1 targetcell= oSheetB.getCellByPosition(0,LastRow) oDocB.CurrentController.Select(targetcell) oFrameB = oDocB.CurrentController.Frame oDispatcher.executeDispatch(oFrameB, ".uno:Paste", "", 0, Dummy()) oDocB.Store oDocB.close(true) 
End Sub`
ChuckyCZ gravatar imageChuckyCZ ( 2019-11-05 13:21:07 +0100 )edit

Please use preformatted text to make your code more readable.

Opaque gravatar imageOpaque ( 2019-11-05 13:50:56 +0100 )edit

I am new so now is OK.

ChuckyCZ gravatar imageChuckyCZ ( 2019-11-06 15:56:21 +0100 )edit