Ubuntu: How to pass two date variables as a concatenated string for destName to copyByName(srcName, destName, index) in LibreOfficeCalc( [closed]


thanks in advance. The Title sums it up fairly succinctly, but for illustrative purposes, here is what I'm trying to do:

Sub Main  dim doc as Object, sheet as Object  doc=ThisComponent  numSheets=doc.Sheets.count()  sheet=doc.Sheets(numSheets-1)  sheetName=sheet.Name  currentDay=Date()  lastDay=sheet.getCellRangeByName("B1").value  mon=Month(lastDay)    Select case mon:      case 1:          monMod=31      case 2:          monMod=28      case 3:          monMod=31      case 4:          monMod=30      case 5:          monMod=31      case 6:          monMod=30      case 7:          monMod=31      case 8:          monMod=31      case 9:          monMod=30      case 10:          monMod=31      case 11:          monMod=30      case 12:          monMod=31  End Select  nextMonEnd=CDate(lastDay+monMod)  If currentDay > lastDay Then      newName$=CDate(lastDay+1) & "-" & CDate(nextMonEnd)      doc.Sheets.copyByName(sheetName, newName$, numSheets) '<--      newSheet=doc.sheets(numSheets)               'this part here is the       newPrevious=newSheet.getCellRangeByName("A1")'snag.Throws a Runtime       newPrevious.string=CDate(lastDay+1)         'Exception, Message: .      newEnd=newSheet.getCellRangeByName("B1")    'I think it's passing a       newEnd.string=CDate(nextMonEnd)             'null, but I don't know  End If                                          'why. Any help would be    End Sub                                         'greatly appreciated  

If I hard-code the destName arg, it runs clean. I've tried several different approaches, but any variable I pass as the destName throws an error. Thanks again, guys and gals.

Amended: With some help(see comments), I came up with this working revision of my macro, all else remaining the same. Posting it for relevance.

nextMonEnd=CDate(lastDay+monMod)  newFirst=CDate(lastDay+1)  newName=CStr(Format(newFirst, "mm-dd-yyyy")) & " " & _  CStr(Format(nextMonEnd, "mm-dd-yyyy"))  If currentDay > lastDay Then        doc.Sheets.copyByName(sheetName, newName, numSheets)      newSheet=doc.sheets(numSheets)      newCurrent=newSheet.getCellRangeByName("A1")      newCurrent.value=lastDay+1      newEnd=newSheet.getCellRangeByName("B1")      newEnd.value=nextMonEnd      print "New Monthly sheet added."  End If  


The problem is that the resulting sheet name contains prohibited characters. In OpenOffice.Calc,

you can only use letters, numbers, spaces, and the underline character in the sheet name.

(OO Calc FAQ)

The sheet name you've built contains slashes /, yielding an invalid sheet name.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »