Home » excel » excel – How to move activesheet to the end of sheets in Lotusscript

excel – How to move activesheet to the end of sheets in Lotusscript

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have an excel file which has already been created. I can open thet excel file then what i want to do is just a add new worksheet then move that worksheet to the end. I found excel VBA codes but I could not convert to Lotusscript. :((

Set xlApp = CreateObject("Excel.application")
xlApp.Visible = True   
xlApp.Workbooks.Open(fileN) 
sheetcount = xlApp.workbooks(1).Worksheets.Count
Set lastsheet = xlapp.workbooks(1).Worksheets(sheetcount)
Set xlsheet = xlapp.workbooks(1).Worksheets.Add(lastsheet)
xlsheet.Name = sheetName 
xlapp.workbooks(1).Worksheets(sheetName).Move(2)

I think This code below will help me but I could not write correct syntax.

Sub MoverToEnd()
    ActiveSheet.Move _
    After: = ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
End Sub
How to&Answers:

This will ultimately solve your problem. Change the sixth line to:

Set xlsheet = xlapp.workbooks(1).Worksheets.Add(,lastsheet)

That will insert the new sheet at the end and return you a Worksheet object so you can change the name.

If you need to use .move(), you have to either capture a return value or use a CALL, for example:

call xlapp.workbooks(1).Worksheets.Move(,lastsheet)

By the way, the parameter of Move isn’t an integer, it’s a worksheet object.