Search notes:

Excel VBA: Worksheet.Copy

Copy a sheet to a new workbook

If worksheet's .copy method is invoked without arguments, a new workbook is created and the sheet is copied unto the new workbook.
option explicit

sub main() ' {

    dim shFoo, shBar, shBaz as workSheet

    set shFoo = createSheet("foo")
    set shBar = createSheet("baz")
    set shBaz = createSheet("bar")

  '
  ' Using copy without arguments creates a
  ' new workbook that contains the copied Worksheet object.
  ' The copied worksheet retains
  '   - its name
  '   - its codeName property
  '
    shBar.copy

  dim newWorkbook as workbook
  set newWorkbook = application.activeWorkbook
  newWorkbook.sheets("Baz").cells(3,2) = "Copied sheet"

end sub ' }

function createSheet(name as string) as workSheet ' {
    set createSheet = activeWorkbook.sheets.add
    createSheet.name = name
    createSheet.cells(2,2) = "This is sheet " & name
end function ' }
Github repository about-MS-Office-object-model, path: /Excel/Worksheet/copy/sheet-to-new-workbook.bas

See also

The copy method of a range.
worksheets.copy()

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1758199678, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Office/Excel/Object-Model/Worksheet/copy(76): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78