Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '**************** CopySheet ********************
- 'copies the contents of the active sheet
- 'to a new sheet, named by the user, and placed as
- 'the last sheet in the workbook.
- '***********************************************
- Sub CopySheet
- dim Sheet1 as String
- dim Sheet2 as String
- dim Doc as Object
- dim NewSheet as Object
- Doc = ThisComponent
- 'This checks to make sure that Doc is a spreadsheet
- If NOT Doc.supportsService("com.sun.star.sheet.SpreadsheetDocument") then
- MsgBox "This Macro Only Works with Calc Spreadsheets"
- Exit Sub
- End If
- Sheet1 = Doc.CurrentController.ActiveSheet.Name
- Sheet2 = InputBox("Enter Name for Copied Sheet:", "Copy Sheet", Sheet1)
- If Sheet2 = "" Then Exit Sub
- Do While Doc.Sheets.hasByName(Sheet2)
- Sheet2 = InputBox(Sheet2 + " already exist, select a different name:", "Copy Sheet", Sheet2 + "2")
- If Sheet2 = "" Then Exit Sub
- Loop
- Doc.Sheets.CopyByName(Sheet1, Sheet2, Doc.Sheets.Count)
- NewSheet = Doc.Sheets.getByName(Sheet2)
- Doc.CurrentController.setActiveSheet(NewSheet)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement