Ask Your Question
0

Calc. Creating few copies of sheet at once

asked 2018-11-25 10:16:12 +0200

Hello. Is there any way to create few copies of selected sheet at once? If i need, for example, 50 copies, making "right click on sheet - remove/copy sheet - copy" 50 times is very tiring.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-11-25 10:38:02 +0200

JohnSUN gravatar image

Hello, yes, it's possible:

Sub CopyActiveSheet
Dim sName As String, sNewName As String, sK As String
Dim oSheets As Variant, i As Long, j As Long, k As Long, m As Long 
  sK = InputBox("How many copies of the current sheet do you need to create?", "Enter number","2")
  k = Val(sK)
  If k < 1 Then Exit Sub 
  sName = ThisComponent.getCurrentController().getActiveSheet().getName()
  oSheets = ThisComponent.getSheets()
  j = 0
  For i = 1 To k
    For m = 1 To 100
      j = j + 1
      sNewName = sName & "_" & j
      If Not oSheets.hasByName(sNewName) Then 
        oSheets.copyByName(sName, sNewName, oSheets.getCount())
        Exit For 
      EndIf 
    Next m
  Next i
End Sub
edit flag offensive delete link more

Comments

Thank you, it worked

ProstoyPolzovatel gravatar imageProstoyPolzovatel ( 2018-11-25 11:28:09 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-11-25 10:16:12 +0200

Seen: 29 times

Last updated: Nov 25 '18