{"id":1984,"date":"2017-11-17T20:56:21","date_gmt":"2017-11-17T20:56:21","guid":{"rendered":"http:\/\/elbsolutions.com\/projects\/?p=1984"},"modified":"2022-02-03T11:24:28","modified_gmt":"2022-02-03T17:24:28","slug":"stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back","status":"publish","type":"post","link":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/","title":{"rendered":"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back!"},"content":{"rendered":"<p>Ok &#8211; <a href=\"https:\/\/www.engram9.info\/excel-vba-programming-3\/the-workbook-and-window-objects.html\">so this guy give me the one tip that mattered<\/a>. Application.Windows(1) is the active window. ALSO &#8211; you can change the caption of the window. IF you have a workbook and need to show\u00a0 2 or more worksheets in as many windows &#8211; then it renames the sheets and adds :1 and :2 &#8211; which DO NOT CHANGE. But the windows(1) is NOT reliably window(1) the next time you interact with the windows.<\/p>\n<p>So if you want sheet1&#8217;s window to return sheet1 and sheet2&#8217;s window to interact with sheet2 &#8211; then here is some code to help one understand what is going on. What I am going to do is change the :1 to :DELTA and :2 to :SOURCE and ensure that those windows show the delta and source worksheets respectively<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\r\nSub Test_WindowIndexes()\r\n' Here is the guy to inspired me to fiddle and get some understanding. It is mental but\r\n' there is some hope is his bottom line. https:\/\/www.engram9.info\/excel-vba-programming-3\/the-workbook-and-window-objects.html\r\n\r\n' before you run this - make a workbook with 2 worksheets\r\n' rename them something memorable\r\n\r\n' Next - simply make a new window . Use hte View Ribbon-&gt;New Window button\r\n' or Set mywb = workbook.newWindow command here in VBA (in future)\r\n\r\nDebug.Print &quot;*********************new&quot; ' just a line so you can see what\r\n'is going on between running this and loooking in the immediate window\r\n\r\n\r\nDebug.Print &quot;activesheet: &quot; &amp; ActiveSheet.Parent.Windows(1).Caption\r\nActiveSheet.Parent.Windows(1).Caption = VBA.Replace(ActiveSheet.Parent.Windows(1).Caption, &quot;:1&quot;, &quot;:DELTA&quot;)\r\nDim vvar As Variant\r\nDim w As Window\r\n\r\n\r\n' lets set aside some static instances of the windows as they are right now\r\nDim winds As New Collection\r\nwinds.Add ActiveSheet.Parent.Windows(1) ' the active screen\r\nwinds.Add ActiveSheet.Parent.Windows(2) ' some random worksheet\r\n\r\n' lets cycle through the worksheets.\r\n' Set a breakpoint AFTER the Next - play with the windows and re-run this loop.\r\n' the Application.windows collection CHANGES INDEXES - how unstable!\r\nFor Each vvar In ActiveSheet.Parent.Windows\r\nSet w = vvar\r\nDebug.Print &quot;collection: &quot; &amp; w.Caption &amp; &quot; --&gt; &quot; &amp; w.ActiveSheet.Name\r\nNext\r\n\r\n' now let VBA muck with the active window\r\nwinds(1).activate\r\nDebug.Print &quot;.windows(1):&quot; &amp; Application.Windows(1).Caption\r\nDebug.Print &quot;w1:&quot; &amp; winds(1).Caption\r\nDebug.Print &quot;w2:&quot; &amp; winds(2).Caption\r\n\r\nDebug.Print &quot; ... now switch to winds(2) as active&quot;\r\nwinds(2).activate\r\nDebug.Print &quot;.windows(1):&quot; &amp; Application.Windows(1).Caption\r\nDebug.Print &quot;w1:&quot; &amp; winds(1).Caption\r\nDebug.Print &quot;w2:&quot; &amp; winds(2).Caption\r\n\r\n\r\n' wind(1) and winds(2) are finally static and no longer dependant on windows(1)\r\n' got a solution now. How mental is this!? Perhaps this was out the Excel Team's area\r\n' of control. The Excel team would not have let this mahem propagte.\r\n\r\n\r\nEnd Sub\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ok &#8211; so this guy give me the one tip that mattered. Application.Windows(1) is the active window. ALSO &#8211; you can change the caption of the window. IF you have a workbook and need to show\u00a0 2 or more worksheets in as many windows &#8211; then it renames the sheets and adds :1 and :2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1984","post","type-post","status-publish","format-standard","hentry","category-general"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back! - ELB Solutions.com Inc.<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back! - ELB Solutions.com Inc.\" \/>\n<meta property=\"og:description\" content=\"Ok &#8211; so this guy give me the one tip that mattered. Application.Windows(1) is the active window. ALSO &#8211; you can change the caption of the window. IF you have a workbook and need to show\u00a0 2 or more worksheets in as many windows &#8211; then it renames the sheets and adds :1 and :2 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/\" \/>\n<meta property=\"og:site_name\" content=\"ELB Solutions.com Inc.\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-17T20:56:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-03T17:24:28+00:00\" \/>\n<meta name=\"author\" content=\"Etienne Bley\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Etienne Bley\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\\\/\"},\"author\":{\"name\":\"Etienne Bley\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#\\\/schema\\\/person\\\/51e717c68f4f5917c63baf88f0896c39\"},\"headline\":\"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back!\",\"datePublished\":\"2017-11-17T20:56:21+00:00\",\"dateModified\":\"2022-02-03T17:24:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\\\/\"},\"wordCount\":494,\"articleSection\":[\"General\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\\\/\",\"url\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\\\/\",\"name\":\"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back! - ELB Solutions.com Inc.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#website\"},\"datePublished\":\"2017-11-17T20:56:21+00:00\",\"dateModified\":\"2022-02-03T17:24:28+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#\\\/schema\\\/person\\\/51e717c68f4f5917c63baf88f0896c39\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#website\",\"url\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/\",\"name\":\"ELB Solutions.com Inc.\",\"description\":\"Bringing all your IT Pieces together\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#\\\/schema\\\/person\\\/51e717c68f4f5917c63baf88f0896c39\",\"name\":\"Etienne Bley\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g\",\"caption\":\"Etienne Bley\"},\"url\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/author\\\/etienne-bley\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back! - ELB Solutions.com Inc.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/","og_locale":"en_US","og_type":"article","og_title":"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back! - ELB Solutions.com Inc.","og_description":"Ok &#8211; so this guy give me the one tip that mattered. Application.Windows(1) is the active window. ALSO &#8211; you can change the caption of the window. IF you have a workbook and need to show\u00a0 2 or more worksheets in as many windows &#8211; then it renames the sheets and adds :1 and :2 [&hellip;]","og_url":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/","og_site_name":"ELB Solutions.com Inc.","article_published_time":"2017-11-17T20:56:21+00:00","article_modified_time":"2022-02-03T17:24:28+00:00","author":"Etienne Bley","twitter_misc":{"Written by":"Etienne Bley","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/#article","isPartOf":{"@id":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/"},"author":{"name":"Etienne Bley","@id":"https:\/\/elbsolutions.com\/projects\/#\/schema\/person\/51e717c68f4f5917c63baf88f0896c39"},"headline":"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back!","datePublished":"2017-11-17T20:56:21+00:00","dateModified":"2022-02-03T17:24:28+00:00","mainEntityOfPage":{"@id":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/"},"wordCount":494,"articleSection":["General"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/","url":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/","name":"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back! - ELB Solutions.com Inc.","isPartOf":{"@id":"https:\/\/elbsolutions.com\/projects\/#website"},"datePublished":"2017-11-17T20:56:21+00:00","dateModified":"2022-02-03T17:24:28+00:00","author":{"@id":"https:\/\/elbsolutions.com\/projects\/#\/schema\/person\/51e717c68f4f5917c63baf88f0896c39"},"breadcrumb":{"@id":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/elbsolutions.com\/projects\/stop-mahem-vba-windows-collection-changes-time-activate-new-windows-get-sense-back\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/elbsolutions.com\/projects\/"},{"@type":"ListItem","position":2,"name":"Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back!"}]},{"@type":"WebSite","@id":"https:\/\/elbsolutions.com\/projects\/#website","url":"https:\/\/elbsolutions.com\/projects\/","name":"ELB Solutions.com Inc.","description":"Bringing all your IT Pieces together","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/elbsolutions.com\/projects\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/elbsolutions.com\/projects\/#\/schema\/person\/51e717c68f4f5917c63baf88f0896c39","name":"Etienne Bley","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g","caption":"Etienne Bley"},"url":"https:\/\/elbsolutions.com\/projects\/author\/etienne-bley\/"}]}},"_links":{"self":[{"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/posts\/1984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/comments?post=1984"}],"version-history":[{"count":1,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/posts\/1984\/revisions"}],"predecessor-version":[{"id":1986,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/posts\/1984\/revisions\/1986"}],"wp:attachment":[{"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/media?parent=1984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/categories?post=1984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/tags?post=1984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}