<?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
      <title>Category: VSTO | Mitja Bezenšek</title>
      <id>http://bezensek.com/</id>
      <link href="https://bezensek.com/blog/categories/vsto/atom.xml" rel="self"/>
      <link href="https://bezensek.com/"/>
      <updated>2014-07-23T10:20:04+01:00</updated>
      <author><name>Mitja Bezenšek</name></author>
      <entry>
      <title type="text">Excel&apos;s ActivePane Index property bug and a workaround</title>
      <id>http://bezensek.com/blog/2014/07/23/excel-activepane-index-property-bug-and-a-workaround</id>
      <link href="https://bezensek.com/excel-activepane-index-property-bug-and-a-workaround/"/>
      <updated>2014-07-23T10:20:04+01:00</updated>
      <published>2014-07-23T10:20:04+01:00</published>
      <content type="html">&lt;p&gt;In &lt;a href=&quot;https://zebrabi.com/&quot;&gt;Zebra BI&lt;/a&gt; we are positioning our custom WPF forms on top of the Excel window in order to offer a richer and more contextual UI. Calculating the exact position for the forms is quite complex and painful, due to things like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;detecting the Excel window state and left edge position&lt;/li&gt;
&lt;li&gt;calculating from points to pixels &lt;sup&gt;&lt;a href=&quot;#user-content-fn-1&quot; id=&quot;user-content-fnref-1&quot; data-footnote-ref aria-describedby=&quot;footnote-label&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;li&gt;coping with the Windows DPI&lt;/li&gt;
&lt;li&gt;taking Ribbon / Formula Bar / Excel version into consideration&lt;/li&gt;
&lt;li&gt;serious lack of events on many of Excel’s objects&lt;/li&gt;
&lt;li&gt;…&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The last nail in the coffin were the Panes which also need to be considered when a user uses the Freeze Panes option, which basically splits the worksheet into 2 or 4 Panes. At first it seemed like a simple adjustment until I started digging into the object model and ultimately found out that:&lt;/p&gt;
&lt;!-- more --&gt;
&lt;h2 id=&quot;activepanes-index-property-doesnt-work-correctly&quot;&gt;ActivePane’s Index property doesn’t work correctly&lt;/h2&gt;
&lt;p&gt;According to the &lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.window.activepane?view=excel-pia&quot;&gt;Excel Object Model&lt;/a&gt; specification the ActivePane property:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Returns a &lt;strong&gt;Pane&lt;/strong&gt; object that represents the &lt;strong&gt;active pane&lt;/strong&gt; in the &lt;strong&gt;window&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;and you can:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Use the &lt;strong&gt;Index&lt;/strong&gt; property to obtain the &lt;strong&gt;index&lt;/strong&gt; of the &lt;strong&gt;active pane&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Here is a simple code that is used to display the index of the current ActivePane:&lt;/p&gt;
&lt;pre class=&quot;astro-code dev-notes&quot; style=&quot;background-color:var(--code-background, #e8e9e3);color:var(--code-foreground, #292a28); overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-type, #176d76)&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; window &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; Globals&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;ThisAddIn&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Application&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;ActiveWindow&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-type, #176d76)&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; activePane &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; window&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;ActivePane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;MessageBox&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-function, #2465aa)&quot;&gt;Show&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;activePane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-function, #2465aa)&quot;&gt;ToString&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;());&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let’s see it in action.&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://bezensek.com/_images/0fb2ef30729aaf97-480.webp 480w, https://bezensek.com/_images/0fb2ef30729aaf97-743.webp 743w&quot; sizes=&quot;(max-width: 540px) calc(100vw - 66px), (max-width: 760px) calc(100vw - 90px), (max-width: 898px) calc(100vw - 158px), 740px&quot;&gt;&lt;img src=&quot;https://bezensek.com/img/ActivePane.gif&quot; alt=&quot;ActivePane&quot; width=&quot;743&quot; height=&quot;500&quot; decoding=&quot;async&quot; loading=&quot;eager&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;As you see when there are 2 panes it &lt;strong&gt;always returns 2&lt;/strong&gt; and when we have 4 panes it &lt;strong&gt;always returns 4&lt;/strong&gt;. I’m guessing it is just returning the number of the panes :)&lt;/p&gt;
&lt;h2 id=&quot;the-workaround&quot;&gt;The workaround&lt;/h2&gt;
&lt;p&gt;I needed to determine in which of the Panes is the current selection so I started looking at the Panes members. The only promising one was the &lt;code&gt;VisibleRange&lt;/code&gt;. I didn’t want to use the Excel function &lt;code&gt;INTERSECT&lt;/code&gt; since is quite costly performance wise. I figured out that just comparing the &lt;code&gt;Left&lt;/code&gt; property of the &lt;code&gt;VisibleRange&lt;/code&gt; with the &lt;code&gt;Left&lt;/code&gt; property of the current selection should be enough (the same for the &lt;code&gt;Top&lt;/code&gt; property). So I came up with this:&lt;/p&gt;
&lt;pre class=&quot;astro-code dev-notes&quot; style=&quot;background-color:var(--code-background, #e8e9e3);color:var(--code-foreground, #292a28); overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:var(--code-function, #2465aa)&quot;&gt; GetPaneIndex&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;(){&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-type, #176d76)&quot;&gt;    Range&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; selection &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; Globals&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;ThisAddIn&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Application&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Selection&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-type, #176d76)&quot;&gt;    var&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; window &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; Globals&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;ThisAddIn&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Application&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;ActiveWindow&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-type, #176d76)&quot;&gt;    var&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; paneCount &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; window&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Panes&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Count&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;paneCount &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-type, #176d76)&quot;&gt;        Pane&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; secondPane &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; window&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Panes&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;secondPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;ScrollRow &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;          &amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; secondPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;VisibleRange&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Top &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; selection&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Top&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;secondPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;ScrollColumn &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;          &amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; secondPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;VisibleRange&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Left &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; selection&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Left&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;           return&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;    else&lt;/span&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;paneCount &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-type, #176d76)&quot;&gt;        Pane&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; secondPane &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; window&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Panes&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-type, #176d76)&quot;&gt;        Pane&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; thirdPane &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; window&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Panes&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;selection&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Left &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; secondPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;VisibleRange&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Left &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;          &amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; selection&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Top &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; thirdPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;VisibleRange&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Top&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;           return&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;selection&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Left &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; secondPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;VisibleRange&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Left &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;          &amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; selection&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Top &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; thirdPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;VisibleRange&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Top&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;           return&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;selection&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Left &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; secondPane&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;VisibleRange&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt;Left &lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;           return&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;     }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;     return&lt;/span&gt;&lt;span style=&quot;color:var(--code-constant, #895b13)&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works just fine with &lt;code&gt;Ranges&lt;/code&gt; and pretty much every Excel object that has &lt;code&gt;Left&lt;/code&gt; and &lt;code&gt;Top&lt;/code&gt; properties. You get the correct index of the &lt;code&gt;ActivePane&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;However, what you also get, are some triggered events as soon as you access the VisibleRange property. I have no clue why this happens. Even a simple assigment like &lt;code&gt;var range = pane.VisibleRange;&lt;/code&gt; causes the active chart to get deactivated, which again caused quite a few additional problems that are beyond the scope of this post.&lt;/p&gt;
&lt;section data-footnotes class=&quot;footnotes&quot;&gt;&lt;h2 class=&quot;sr-only&quot; id=&quot;footnote-label&quot;&gt;Footnotes&lt;/h2&gt;
&lt;ol&gt;
&lt;li id=&quot;user-content-fn-1&quot;&gt;
&lt;p&gt;Since the &lt;code&gt;PointsToScreenPixels&lt;/code&gt; method is bugged as well. &lt;a href=&quot;#user-content-fnref-1&quot; data-footnote-backref=&quot;&quot; aria-label=&quot;Back to reference 1&quot; class=&quot;data-footnote-backref&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
    </entry>
    </feed>