Hello I have had code to copy an existing spreadsheet into a brand new one for years and all of a sudden it stopped working. I can’t seem to find anything on the web that states what change might of happened. I am hoping someone here would be able to shed some light on it.
Here is the code that I have for copying a spreadsheet.
Sub copyCurrentSheet
mFile = Month(Date)
Select Case mFile
Case 1
fileDate1 = "Jan "
Case 2
fileDate1 = "Feb "
Case 3
fileDate1 = "Mar "
Case 4
fileDate1 = "Apr "
Case 5
fileDate1 = "May "
Case 6
fileDate1 = "Jun "
Case 7
fileDate1 = "Jul "
Case 8
fileDate1 = "Aug "
Case 9
fileDate1 = "Sep "
Case 10
fileDate1 = "Oct "
Case 11
fileDate1 = "Nov "
Case 12
fileDate1 = "Dec "
End Select
fileDate2 = fileDate1 & Day(Date) & "," & Year(Date)
fileDate1 = fileDate2
doc1 = ThisComponent
oSheets = doc1.getSheets()
y = "1"
fileNameExists = "yyyyy"
Do While fileNameExists <> "xxxxx"
If oSheets.hasByName(fileDate1) Then
y = y + 1
fileDate1 = fileDate2 & " " & y
Else
fileNameExists = "xxxxx"
End If
Loop
doc1 = ThisComponent
oSheet1 = StarDesktop.CurrentComponent.CurrentController.ActiveSheet
oSheet2 = oSheet1
currentSheet = oSheet1.getName()
selectSheetByName(doc1, currentSheet)
dispatchURL(doc1,".uno:SelectAll")
dispatchURL(doc1,".uno:Copy")
doc1.getSheets().insertNewByName(fileDate1, 0)
selectSheetByName(doc1, fileDate1)
dispatchURL(doc1,".uno:Paste")
oSheet1 = StarDesktop.CurrentComponent.CurrentController.ActiveSheet
printerOption(0).Name = "PaperOrientation"
printerOption(0).Value = com.sun.star.view.PaperOrientation.LANDSCAPE
thisComponent.Printer = printerOption()
oSheet1.setPrintareas (oSheet2.getPrintareas())
doc1 = ThisComponent
oController = doc1.getCurrentController ' freezes active sheet
oController.freezeAtPosition(11,2)
oCell=oSheet1.getCellRangeByName("F1")
oCell.setValue(DateValue(Now))
oCell.NumberFormat=75
oCell = oSheet1.getCellRangeByName("C4")
ThisComponent.CurrentController.select(oCell)
Thiscomponent.getSheets().getByName(oSheet1.getName()).Protect("")
End Sub
(Edited for better readability by @Lupp)