snipt

Ctrl+h for KB shortcuts

C#

Get Worksheet object by name

1
2
3
using Excel = Microsoft.Office.Interop.Excel;

Excel.Worksheet worksheet = (Excel.Worksheet)Globals.ThisWorkbook.Worksheets["SheetName"];
https://snipt.net/embed/d1d482e015b9d2eafcb1828a2e40d380/
/raw/d1d482e015b9d2eafcb1828a2e40d380/
d1d482e015b9d2eafcb1828a2e40d380
csharp
C#
3
2019-08-17T17:54:03
True
False
False
/api/public/snipt/38002/
get-worksheet-object-by-name
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">using</span> <span class="nn">Excel</span> <span class="p">=</span> <span class="n">Microsoft</span><span class="p">.</span><span class="n">Office</span><span class="p">.</span><span class="n">Interop</span><span class="p">.</span><span class="n">Excel</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="n">Excel</span><span class="p">.</span><span class="n">Worksheet</span> <span class="n">worksheet</span> <span class="p">=</span> <span class="p">(</span><span class="n">Excel</span><span class="p">.</span><span class="n">Worksheet</span><span class="p">)</span><span class="n">Globals</span><span class="p">.</span><span class="n">ThisWorkbook</span><span class="p">.</span><span class="n">Worksheets</span><span class="p">[</span><span class="s">&quot;SheetName&quot;</span><span class="p">];</span> </span></pre></div> </td></tr></table>
vsto