{"id":9,"date":"2026-01-22T11:16:00","date_gmt":"2026-01-22T03:16:00","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=9"},"modified":"2026-01-17T04:21:23","modified_gmt":"2026-01-17T04:21:23","slug":"how-to-activate-copy-move-and-delete-worksheets-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-activate-copy-move-and-delete-worksheets-using-xlwings\/","title":{"rendered":"How To Activate, Copy, Move, and Delete Worksheets Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<h3 style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">Activate a worksheet<\/span><\/h3>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">bk.sheets[1].activate()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.sheets[1].select()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings API<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Worksheets(2).Activate()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Worksheets(2).Select()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 10.0pt;\">\u00a0<\/p>\n<h3 style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">Copy worksheets <\/span><\/h3>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings API<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Sheets(&#8216;Sheet1&#8217;).Copy(Before=bk.api.Sheets(&#8216;Sheet2&#8217;))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Sheets(&#8216;Sheet1&#8217;).Copy(After=bk.api.Sheets(&#8216;Sheet2&#8217;))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 10.0pt;\">\u00a0<\/p>\n<h3 style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">Copy across workbooks<\/span><\/h3>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Sheets(&#8216;Sheet1&#8217;).Copy(Before=bk2.api.Sheets(&#8216;Sheet2&#8217;))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Sheets(&#8216;Sheet1&#8217;).Copy(After=bk2.api.Sheets(&#8216;Sheet2&#8217;))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 10.0pt;\">\u00a0<\/p>\n<h3 style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">Move worksheets<\/span><\/h3>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings API<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Sheets(&#8216;Sheet1&#8217;).Move(Before=bk.api.Sheets(&#8216;Sheet3&#8217;))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Sheets(&#8216;Sheet1&#8217;).Move(After=bk.api.Sheets(&#8216;Sheet3&#8217;))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.Sheets([&#8216;Sheet2&#8217;, &#8216;Sheet3&#8217;]).Move(Before=bk.Sheets(1))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 10.0pt;\">\u00a0<\/p>\n<h3 style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">Delete worksheets<\/span><\/h3>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.sheets(&#8216;Sheet1&#8217;).delete()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.sheets([&#8216;Sheet2&#8217;, &#8216;Sheet3&#8217;]).delete()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings API<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Sheets(&#8216;Sheet1&#8217;).Delete()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Sheets([&#8216;Sheet2&#8217;, &#8216;Sheet3&#8217;]).Delete()<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Activating, Copying, Moving, and Deleting Worksheets\n\nimport xlwings as xw    #Import the xlwings package\n\napp=xw.App()\nbk=app.books.active    #Get the active workbook\nsht=bk.sheets.active\nsht2=bk.sheets.add()\nsht3=bk.sheets.add()\nsht4=bk.sheets.add()\n\n#Activate a worksheet\n#xlwings\nbk.sheets&#91;1].activate()\n#bk.sheets&#91;1].select()\n\n#xlwings API\n#bk.api.Worksheets(2).Activate()\n#bk.api.Worksheets(2).Select()\n\n#Copy worksheets \n#xlwings API\n#bk.api.Sheets('Sheet1').Copy(Before=bk.api.Sheets('Sheet2'))\n#bk.api.Sheets('Sheet1').Copy(After=bk.api.Sheets('Sheet2'))\n\n#Copy across workbooks\n#bk.api.Sheets('Sheet1').Copy(Before=bk2.api.Sheets('Sheet2'))\n#bk.api.Sheets('Sheet1').Copy(After=bk2.api.Sheets('Sheet2'))\n\n#Move worksheets\n#xlwings API\n#bk.api.Sheets('Sheet1').Move(Before=bk.api.Sheets('Sheet3'))\n#bk.api.Sheets('Sheet1').Move(After=bk.api.Sheets('Sheet3'))\n#bk.Sheets(&#91;'Sheet2', 'Sheet3']).Move(Before=bk.Sheets(1))\n\n#Delete worksheets\n#xlwings\n#bk.sheets('Sheet1').delete()\n#bk.sheets(&#91;'Sheet2', 'Sheet3']).delete()\n\n#xlwings API\n#bk.api.Sheets('Sheet1').Delete()\n#bk.api.Sheets(&#91;'Sheet2', 'Sheet3']).Delete()\n\n#bk.close()\n#app.kill()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-xlwings-worksheet"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/9\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}