<?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
      <title>Category: Excel | Mitja Bezenšek</title>
      <id>http://bezensek.com/</id>
      <link href="https://bezensek.com/blog/categories/excel/atom.xml" rel="self"/>
      <link href="https://bezensek.com/"/>
      <updated>2014-08-05T09:45:04+01:00</updated>
      <author><name>Mitja Bezenšek</name></author>
      <entry>
      <title type="text">Excel VSTO RGB Color bug</title>
      <id>http://bezensek.com/blog/2014/08/05/excel-rgb-color-bug</id>
      <link href="https://bezensek.com/excel-rgb-color-bug/"/>
      <updated>2014-08-05T09:45:04+01:00</updated>
      <published>2014-08-05T09:45:04+01:00</published>
      <content type="html">&lt;p&gt;One of the strangest bugs I found in VSTO for Excel is the one that deals with assigning colors to the RGB property of the ChartFormat object. The ChartFormat object is used in multiple places of Excel. Let’s look at an example:&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;Series&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; series &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-foreground, #292a28)&quot;&gt;series&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;Format&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;Fill&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;ForeColor&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;RGB &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; Color&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;Red&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;ToArgb&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;For brevity’s sake let’s suppose that we have a series of a chart selected and we run the code above. One would expect that the color of the selected series would be set to red, but what happens is this:&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://bezensek.com/_images/068ad9e6f2efb965-508.webp 508w&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/chart.png&quot; alt=&quot;Chart&quot; width=&quot;508&quot; height=&quot;317&quot; decoding=&quot;async&quot; loading=&quot;eager&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;!-- more --&gt;
&lt;p&gt;And if we try to color the series blue then the result is red!&lt;/p&gt;
&lt;h2 id=&quot;red-and-blue-components-of-the-rgb-property-are-reversed&quot;&gt;Red and Blue components of the RGB property are reversed&lt;/h2&gt;
&lt;p&gt;Since I intentionally used the red color that resulted in a blue series on the chart, some of you might have figured out the bug. But imagine yourself trying to apply some color from the middle of the RGB color range and consitently getting the wrong results.&lt;/p&gt;
&lt;p&gt;Well the workaround is easy: just use a wrapper function that swaps the red and blue components of the color:&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; void&lt;/span&gt;&lt;span style=&quot;color:var(--code-function, #2465aa)&quot;&gt; ApplyColorToSeries&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;    Series&lt;/span&gt;&lt;span style=&quot;color:var(--code-foreground, #292a28)&quot;&gt; series &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-foreground, #292a28)&quot;&gt;    series&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;Format&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;Fill&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;ForeColor&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;RGB &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; InteropColor&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;255&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; 0&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; 0&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&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--code-keyword, #9f3e2b)&quot;&gt;public&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; InteropColor&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;(&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-foreground, #292a28)&quot;&gt; red&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;,&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-foreground, #292a28)&quot;&gt; green&lt;/span&gt;&lt;span style=&quot;color:var(--code-punctuation, #62635d)&quot;&gt;,&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-foreground, #292a28)&quot;&gt; blue&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-foreground, #292a28)&quot;&gt; Color&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;FromArgb&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;blue&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; green&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; red&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;ToArgb&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;After searching the web I found that this bug has already been mentioned on the &lt;a href=&quot;https://stackoverflow.com/questions/7423456/changing-an-excel-cells-backcolor-using-hex-results-in-excel-displaying-complet&quot;&gt;StackOverflow&lt;/a&gt;. It is interesting that this has not yet been fixed in the newer versions of Excel. I have first stumbled upon this issue with the Excel 2007 interop library but it is still present in the current one. The only reason that comes to my mind is backwards compatibility with the numerous Excel solutions out there. So it seems we should just get used to it.&lt;/p&gt;
&lt;h2 id=&quot;update&quot;&gt;Update:&lt;/h2&gt;
&lt;p&gt;It seems that this is not an Excel interop bug. Apparently the reason for this strange behavior is that VBA has a different representation of colors. For more see the comments.&lt;/p&gt;
</content>
    </entry>
<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/664b698ff835f903-480.webp 480w, https://bezensek.com/_images/664b698ff835f903-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>
<entry>
      <title type="text">The best way to get to know Excel Object Model</title>
      <id>http://bezensek.com/blog/2014/03/24/the-best-way-to-get-to-know-excel-object-model</id>
      <link href="https://bezensek.com/the-best-way-to-get-to-know-excel-object-model/"/>
      <updated>2014-03-24T21:10:04+01:00</updated>
      <published>2014-03-24T21:10:04+01:00</published>
      <content type="html">&lt;p&gt;I am starting a category called “excel Excel” which will contain useful tips and tricks for Excel. It will be mostly directed towards Excel developers and power users.&lt;/p&gt;
&lt;h2 id=&quot;how-do-i-blank-in-excel&quot;&gt;How do I [blank] in Excel?&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/&quot;&gt;StackOverflow&lt;/a&gt; is full of questions like:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“How do I change the color of a Chart Series in Excel in VBA / C#?”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;While doing it manually is easy, the problem occurs when you wish to start talking to Excel from the code. This is not surprising, considering the number of different objects present in the &lt;a href=&quot;https://learn.microsoft.com/en-us/visualstudio/vsto/excel-object-model-overview?view=visualstudio&quot;&gt;Excel Object Model&lt;/a&gt;. One can spend an insane amount of time trying to figure out the exact five steps to reach the desired effect. It is easy to get lost in all the objects, and their methods and properties. Which is why I love the &lt;strong&gt;macro recording option&lt;/strong&gt;.&lt;/p&gt;
&lt;!-- more --&gt;
&lt;p&gt;After learning about it you will be able to do all the tasks you already know how to do manually in code as well. Well, almost all. I’ll write about this in a future post.&lt;/p&gt;
&lt;p&gt;The primary use of macro recording is to &lt;strong&gt;automate repetitive tasks&lt;/strong&gt;. You just start the recording, perform the task and stop the recording. After that you can replay the recorded macro as many times as you wish. And not only that, you can also &lt;strong&gt;see all the steps&lt;/strong&gt; that were performed in code!&lt;/p&gt;
&lt;h2 id=&quot;how-to-record-a-macro&quot;&gt;How to record a macro&lt;/h2&gt;
&lt;p&gt;First of all I recommend that you show the Developer ribbon tab. You can do this under File | Options | Customize Ribbon, where you need to check the Developer ribbon tab:&lt;/p&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://bezensek.com/_images/73cd806279391111-870.webp 870w&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/enableDeveloperRibbon.png&quot; alt=&quot;Enable developer ribbon&quot; width=&quot;870&quot; height=&quot;443&quot; decoding=&quot;async&quot; loading=&quot;eager&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;After enabling the tab you gain access to macro recording and viewing options. You are now ready to record your first macro:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click on the Record macro button under Developer tab&lt;/li&gt;
&lt;li&gt;Perform the selected task, like changing a color of a Chart Series&lt;/li&gt;
&lt;li&gt;Stop the macro recording&lt;/li&gt;
&lt;li&gt;View the results&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://bezensek.com/_images/ca7e7d5b98b790a1-753.webp 753w&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/recordMacro.gif&quot; alt=&quot;Record macro Excel&quot; width=&quot;753&quot; height=&quot;596&quot; decoding=&quot;async&quot; loading=&quot;lazy&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;As you can see at the end of the animation all of the steps that I performed during the recording are saved in the macro. It is now easy to find the object / property you need. I use this extensively, almost every day. It mainly serves as a way of finding the specific object / property to set, after which I use the Intellisense to explore the options a bit further.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you will be using the described technique as much as I do, I even recommend adding it to the Quick Access Toolbar. Click on the arrows in the Toolbar, Select More commands and then add Record macro and View macro commands to your Toolbar:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;picture&gt;&lt;source type=&quot;image/webp&quot; srcset=&quot;https://bezensek.com/_images/6dbdab9f75b16366-448.webp 448w&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/quickAccess.png&quot; alt=&quot;Quick access toolbar customization&quot; width=&quot;448&quot; height=&quot;402&quot; decoding=&quot;async&quot; loading=&quot;lazy&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
</content>
    </entry>
    </feed>