<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title><![CDATA[菜根2 2018-2028 - 特色代码]]></title>
<link>http://www.niaochao2008.com/20180311/</link>
<description><![CDATA[菜菜的时光！]]></description>
<language>zh-cn</language>
<copyright><![CDATA[Copyright 2005 PBlog3 v2.8]]></copyright>
<webMaster><![CDATA[shopsha2002@126.com(菜菜)]]></webMaster>
<generator>PBlog2 v2.4</generator> 
<image>
	<title>菜根2 2018-2028</title>
	<url>http://www.niaochao2008.com/20180311/images/logos.gif</url>
	<link>http://www.niaochao2008.com/20180311/</link>
	<description>菜根2 2018-2028</description>
</image>

			<item>
			<link>http://www.niaochao2008.com/20180311/article.asp?id=135</link>
			<title><![CDATA[多条件查询及姓名加序号标识唯一性]]></title>
			<author>shopsha2002@126.com(admin)</author>
			<category><![CDATA[特色代码]]></category>
			<pubDate>Mon,03 Jul 2023 15:51:25 +0800</pubDate>
			<guid>http://www.niaochao2008.com/20180311/default.asp?id=135</guid>
		<description><![CDATA[<p>&nbsp;双条件查询：</p>
<div>=LOOKUP(1,0/(($A$2:$A$13=F2)*($B$2:$B$13=G2)),$D$2:$D$13)</div>
<div>&nbsp;</div>
<div>姓名后加序号，以标记唯一性的公式：</div>
<div>=C4&amp;COUNTIF($C$4:C4,C4)</div>]]></description>
		</item>
		
			<item>
			<link>http://www.niaochao2008.com/20180311/article.asp?id=113</link>
			<title><![CDATA[VLOOKUP及index+match组合]]></title>
			<author>shopsha2002@126.com(admin)</author>
			<category><![CDATA[特色代码]]></category>
			<pubDate>Fri,27 Aug 2021 22:20:56 +0800</pubDate>
			<guid>http://www.niaochao2008.com/20180311/default.asp?id=113</guid>
		<description><![CDATA[<p>&nbsp;表头名称一致即可自动读取</p>
<div>=VLOOKUP($A2,'2020秋_总源表20200925'!$A$1:$AZ$132,MATCH(B$1,'2020秋_总源表20200925'!$A$1:$AZ$1,0),0)</div>
<div>index+match组合</div>
<div>=INDEX(E:E,MATCH($C447,$C:$C,0)) , e:e为要读取出的列对象，如某科成绩或性别的列，match为要查找匹配的列对象及具体单元格的对象，如姓名列及该列某个单元格的姓名对象。</div>]]></description>
		</item>
		
			<item>
			<link>http://www.niaochao2008.com/20180311/article.asp?id=96</link>
			<title><![CDATA[如何用VBA代码查询两列数据差异？]]></title>
			<author>shopsha2002@126.com(admin)</author>
			<category><![CDATA[特色代码]]></category>
			<pubDate>Thu,30 Jul 2020 18:34:55 +0800</pubDate>
			<guid>http://www.niaochao2008.com/20180311/default.asp?id=96</guid>
		<description><![CDATA[<p>&nbsp;Sub CheckDataDiff()</p>
<div>&nbsp; &nbsp; Dim d As Object</div>
<div>&nbsp; &nbsp; Dim aData1, aData2, aRes, aKeys</div>
<div>&nbsp; &nbsp; Dim strKey As String, strMsg As String</div>
<div>&nbsp; &nbsp; Dim i As Long, k As Long</div>
<div>&nbsp; &nbsp; Dim intSame As Long, intShtA As Long, intShtB As Long</div>
<div>&nbsp; &nbsp; Set d = CreateObject(&quot;scripting.dictionary&quot;) '后期绑定字典</div>
<div>&nbsp; &nbsp; With Worksheets(&quot;表1&quot;) '表1 A列数据存入数组</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; aData1 = .Range(&quot;a1:a&quot; &amp; .Cells(Rows.Count, 1).End(xlUp).Row)</div>
<div>&nbsp; &nbsp; End With</div>
<div>&nbsp; &nbsp; With Worksheets(&quot;表2&quot;) '表2 A列数据存入数组</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; aData2 = .Range(&quot;a1:a&quot; &amp; .Cells(Rows.Count, 1).End(xlUp).Row)</div>
<div>&nbsp; &nbsp; End With</div>
<div>&nbsp; &nbsp; For i = 2 To UBound(aData1) '遍历表1数据存入字典</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; strKey = aData1(i, 1)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; d(strKey) = &quot;表1&quot; '将来源作为item</div>
<div>&nbsp; &nbsp; Next</div>
<div>&nbsp; &nbsp; ReDim aRes(1 To UBound(aData1) + UBound(aData2), 1 To 3) '定义结果数组大小</div>
<div>&nbsp; &nbsp; For i = 2 To UBound(aData2) '遍历表2数据</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; strKey = aData2(i, 1)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; If d.exists(strKey) Then '如果存在关键字&hellip;&hellip;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If d(strKey) = &quot;表1&quot; Then '如果该关键字属于表1，这层判断是为了避免表2存在重复值</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intSame = intSame + 1 '累加相同个数</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aRes(intSame, 1) = strKey '存入结果数组第1列</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d(strKey) = &quot;相同&quot; '将关键字对应的item修改为相同</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Else '如果字典不存在该关键字，说明是表2独有</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intShtB = intShtB + 1 '累加B表独有个数</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aRes(intShtB, 3) = strKey '存入结果数组第3列</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d(strKey) = &quot;表2&quot; '存入字典，item为来源表2</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; End If</div>
<div>&nbsp; &nbsp; Next</div>
<div>&nbsp; &nbsp; aKeys = d.keys '字典的keys集合</div>
<div>&nbsp; &nbsp; For i = 0 To UBound(aKeys) '遍历字典剔除tiem相同的即为A表独有值</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; strKey = aKeys(i)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; If d(strKey) = &quot;表1&quot; Then</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intShtA = intShtA + 1 '累加A表独有个数</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aRes(intShtA, 2) = strKey '存入结果数组第2列</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; End If</div>
<div>&nbsp; &nbsp; Next</div>
<div>&nbsp; &nbsp; If k &lt; intSame Then k = intSame</div>
<div>&nbsp; &nbsp; If k &lt; intShtA Then k = intShtA</div>
<div>&nbsp; &nbsp; If k &lt; intShtB Then k = intShtB</div>
<div>&nbsp; &nbsp; Worksheets(&quot;结果&quot;).Select</div>
<div>&nbsp; &nbsp; Range(&quot;a:e&quot;).ClearContents</div>
<div>&nbsp; &nbsp; Range(&quot;a1&quot;).Resize(UBound(aData1), 1) = aData1 'A列放表1数据</div>
<div>&nbsp; &nbsp; Range(&quot;b1&quot;).Resize(UBound(aData2), 1) = aData2 'B列放表2数据</div>
<div>&nbsp; &nbsp; Range(&quot;a1:e1&quot;) = Array(&quot;A表数据&quot;, &quot;B表数据&quot;, &quot;相同项&quot;, &quot;A表独有&quot;, &quot;B表独有&quot;)</div>
<div>&nbsp; &nbsp; Range(&quot;c2&quot;).Resize(k, UBound(aRes, 2)) = aRes '结果数组数据</div>
<div>&nbsp; &nbsp; strMsg = &quot;两表相同项：&quot; &amp; intSame &amp; vbCrLf _</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp; &quot;A表独有项：&quot; &amp; intShtA &amp; vbCrLf _</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp; &quot;B表独有项：&quot; &amp; intShtB</div>
<div>&nbsp; &nbsp; MsgBox strMsg, , &quot;公众号Excel星球&quot;</div>
<div>&nbsp; &nbsp; Set d = Nothing</div>
<div>End Sub</div>
<div>&nbsp;</div>
<div>
<div>代码解析▼</div>
<div>&nbsp;</div>
<div>第8行至第10行代码将表1 A列的数据存入数组aData1。</div>
<div>&nbsp;</div>
<div>第11行至第13行代码将表2 A列的数据存入数组aData2。</div>
<div>&nbsp;</div>
<div>第14行至第17行代码遍历aData1的数据，作为关键字存入字典，并将对应的item设置为来源表的名字&quot;表1&quot;。</div>
<div>&nbsp;</div>
<div>第18行代码声明一个结果数组aRes。结果数组的行数原本是未知的，但最大行不会超过两个数据源行数的合计值；列数是已知的，有3列，第1列存放两表相同项，第2列存放A表独有项，第3列存放B表独有项。</div>
<div>&nbsp;</div>
<div>第19至第32行代码遍历数组aData2。</div>
<div>&nbsp;</div>
<div>第20行代码将aData2的数据赋值字符串变量strKey。</div>
<div>&nbsp;</div>
<div>第21行代码判断字典中是否存在strKey。</div>
<div>&nbsp;</div>
<div>如果存在，同时对应的item为表1，则说明该值属于两表相同项，存入结果数组第1列。</div>
<div>&nbsp;</div>
<div>如果不存在，说明该值B表独有，则存入结果数组第3列，即B表独有项；同时将该值存入字典，item设置为&quot;表2&quot;，避免表2存在重复值时，结果数组出现项目重复统计问题。</div>
<div>&nbsp;</div>
<div>第33行至第40代码遍历字典的Key，如果Key对应的Item为&quot;表1&quot;，则说明是表1独有项，存入结果数组第2列。</div>
<div>&nbsp;</div>
<div>第41行至第43行代码通过比较运算，获取结果数组有效行的最大行数，赋值变量k。</div>
<div>&nbsp;</div>
<div>第49行代码将结果数组的数据写入工作表单元格区域。</div>
<div>&nbsp;</div>
<div>第50行和第51行代码弹窗告知用户相同项、两表独有项的数目。</div>
<div>&nbsp;</div>
</div>]]></description>
		</item>
		
			<item>
			<link>http://www.niaochao2008.com/20180311/article.asp?id=93</link>
			<title><![CDATA[使用ADO和SQL在Excel工作表中执行查询操作的代码]]></title>
			<author>shopsha2002@126.com(admin)</author>
			<category><![CDATA[特色代码]]></category>
			<pubDate>Sun,23 Feb 2020 18:08:35 +0800</pubDate>
			<guid>http://www.niaochao2008.com/20180311/default.asp?id=93</guid>
		<description><![CDATA[<div>&nbsp;Sub ReadFromWorksheetADO()</div>
<div>&nbsp; &nbsp; Dim wksData As Worksheet</div>
<div>&nbsp; &nbsp; Dim wksResult As Worksheet</div>
<div>&nbsp; &nbsp; Set wksData =ThisWorkbook.Worksheets(&quot;Sheet2&quot;)</div>
<div>&nbsp; &nbsp; Set wksResult =ThisWorkbook.Worksheets(&quot;Sheet3&quot;)</div>
<div>&nbsp; &nbsp; '清除已存在的数据</div>
<div>&nbsp; &nbsp; wksResult.Cells.ClearContents</div>
<div>&nbsp; &nbsp; Dim conn As New ADODB.Connection</div>
<div>&nbsp; &nbsp; conn.Open&quot;Provider=Microsoft.ACE.OLEDB.12.0;&quot; &amp; _</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &quot;Data Source=&quot; &amp;ThisWorkbook.FullName &amp; &quot;;&quot; &amp; _</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;ExtendedProperties=&quot;&quot;Excel 12.0;HDR=Yes;&quot;&quot;;&quot;</div>
<div>&nbsp; &nbsp; '在字符串中存储查询语句</div>
<div>&nbsp; &nbsp; Dim query As String</div>
<div>&nbsp; &nbsp; query = &quot;Select * from [&quot; &amp;wksData.Name _</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp; &quot;$] Where 物品='苹果' &quot;</div>
<div>&nbsp; &nbsp; '运行查询并存储在记录集中</div>
<div>&nbsp; &nbsp; Dim rs As New Recordset</div>
<div>&nbsp; &nbsp; rs.Open query, conn</div>
<div>&nbsp; &nbsp; '输入标题</div>
<div>&nbsp; &nbsp; Dim i As Long</div>
<div>&nbsp; &nbsp; For i = 0 To rs.Fields.Count - 1</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; wksResult.Cells(1, i + 1).Value2 =rs.Fields(i).Name</div>
<div>&nbsp; &nbsp; Next i</div>
<div>&nbsp; &nbsp; '输入数据</div>
<div>&nbsp; &nbsp;wksResult.Range(&quot;A2&quot;).CopyFromRecordset rs</div>
<div>&nbsp; &nbsp; '关闭连接</div>
<div>&nbsp; &nbsp; conn.Close</div>
<div>End Sub</div>
<div>&nbsp;</div>
<div>代码中，打开并连接数据库的语句为：</div>
<div>&nbsp;</div>
<div>conn.Open&quot;Provider=Microsoft.ACE.OLEDB.12.0;&quot; &amp; _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &quot;Data Source=&quot; &amp;ThisWorkbook.FullName &amp; &quot;;&quot; &amp; _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &quot;Extended Properties=&quot;&quot;Excel12.0;HDR=Yes;&quot;&quot;;&quot;</div>
<div>&nbsp;</div>
<div>适用于2007及以上版本。在同一代码中，只需要连接数据库一次，接着可以执行多个查询操作，无需每次查询前都进行连接。</div>
<div>&nbsp;</div>
<div>SQL查询语句为：</div>
<div>&nbsp;</div>
<div>query = &quot;Select * from [&quot; &amp; wksData.Name _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &amp; &quot;$] Where 物品='苹果' &quot;</div>
<div>&nbsp;</div>
<div>在工作表wksData中查询物品为&ldquo;苹果&rdquo;的记录，*号表示获取记录的所有字段。</div>
<div>&nbsp;</div>
<div>我们还可以设置其他条件查询，获得相应的记录。例如：</div>
<div>&nbsp;</div>
<div>1.查询物品为&ldquo;苹果&rdquo;且数量大于等于100的记录。</div>
<div>&nbsp;</div>
<div>query = &quot;Select * from [&quot; &amp; wksData.Name _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &amp; &quot;$] Where 物品='苹果' and 数量&gt;=100&quot;</div>
<div>&nbsp;</div>
<div>2. 查询物品为&ldquo;苹果&rdquo;或者数量大于等于100的记录。</div>
<div>&nbsp;</div>
<div>query = &quot;Select * from [&quot; &amp; wksData.Name _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &amp; &quot;$] Where 物品='苹果' or 数量&gt;=100&quot;</div>
<div>&nbsp;</div>
<div>3.查询编号以12开头的记录。</div>
<div>&nbsp;</div>
<div>query = &quot;Select * from [&quot; &amp; wksData.Name _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &amp; &quot;$] Where 编号 like '12%' &quot;</div>
<div>&nbsp;</div>
<div>4.查询编号以1结尾的记录。</div>
<div>&nbsp;</div>
<div>query = &quot;Select * from [&quot; &amp; wksData.Name _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &amp; &quot;$] Where 编号 like '%1' &quot;</div>
<div>&nbsp;</div>
<div>5.查询编号中包含200的记录。</div>
<div>&nbsp;</div>
<div>query = &quot;Select * from [&quot; &amp; wksData.Name _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &amp; &quot;$] Where 编号 like '%200%' &quot;</div>
<div>&nbsp;</div>
<div>也可以选择获取满足条件的记录中的字段。例如，查找并获取物品为&ldquo;苹果&rdquo;的记录中的编号、物品和单价：</div>
<div>&nbsp;</div>
<div>query = &quot;Select 编号,物品,单价 from [&quot; &amp; wksData.Name _</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &nbsp;&amp; &quot;$] Where 物品='苹果' &quot;</div>
<div>&nbsp;</div>
<div>来源：</div>
<div>https://cloud.tencent.com/developer/article/1467282</div>
<div>&nbsp;</div>
<p>&nbsp;</p>]]></description>
		</item>
		
			<item>
			<link>http://www.niaochao2008.com/20180311/article.asp?id=92</link>
			<title><![CDATA[在excel中引用ADO类库的两种方法]]></title>
			<author>shopsha2002@126.com(admin)</author>
			<category><![CDATA[特色代码]]></category>
			<pubDate>Sun,23 Feb 2020 17:58:34 +0800</pubDate>
			<guid>http://www.niaochao2008.com/20180311/default.asp?id=92</guid>
		<description><![CDATA[<p>&nbsp;在VBA中引用ADO类库一般有两种方式。</p>
<div>&nbsp;</div>
<div>一种是前期绑定。</div>
<div>&nbsp;</div>
<div>所谓前期绑定，是指在VBE中手工勾选引用Microsoft ADO相关类库。</div>
<div>&nbsp;</div>
<div>在Excel中，按&lt;Alt+F11&gt;快捷键打开VBA编辑窗口，依次单击【工具】&rarr;【引用】，打开【引用-VBAProject】对话框。在【可使用的引用】列表框中，勾选&ldquo;Microsoft ActiveX Data Objects 2.8 Library&rdquo;库，或&ldquo;Microsoft ActiveX Data Objects 6.1 Library&rdquo;库，单击【确定】按钮关闭对话框。</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>另一种是使用代码后期绑定。</div>
<div>&nbsp;</div>
<div>Sub 后期绑定()</div>
<div>&nbsp; &nbsp; Dim cnn As Object</div>
<div>&nbsp; &nbsp; Set cnn = CreateObject(&quot;adodb.connection&quot;)</div>
<div>End Sub</div>
<div>&nbsp;</div>
<div>两种方式的主要区别是，前期绑定后，在代码编辑过程中，VBE的&ldquo;自动列出成员&rdquo;功能，可以提供ADO的属性和方法，这便于代码快捷、准确的编写，但当他人的Excel工作簿并没有手工前期绑定ADO类库时，相关代码将无法运行；因此后期代码绑定ADO的通用性会更强些，它不需要手工绑定相关类库。</div>
<div>来源：https://mp.weixin.qq.com/s?__biz=MzI0MTAxNTc5NA==&amp;mid=2468634477&amp;idx=3&amp;sn=47e652209bab466e8bab3e27cd38a58d&amp;chksm=ffc2f1f0c8b578e6e7ea0fac79289ff858e82641dd740e45e3135644a895fd74a550061bdf99&amp;scene=21#wechat_redirect</div>]]></description>
		</item>
		
			<item>
			<link>http://www.niaochao2008.com/20180311/article.asp?id=91</link>
			<title><![CDATA[各版本ExcelAdo连接代码]]></title>
			<author>shopsha2002@126.com(admin)</author>
			<category><![CDATA[特色代码]]></category>
			<pubDate>Sun,23 Feb 2020 17:46:13 +0800</pubDate>
			<guid>http://www.niaochao2008.com/20180311/default.asp?id=91</guid>
		<description><![CDATA[<p>&nbsp;07~19版本ExcelAdo连接代码：</p>
<p><span style="font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; color: rgb(51, 51, 51); font-size: 14px; letter-spacing: 0.544px;">Sub test()</span></p>
<pre class="code-snippet__js" data-lang="sql" style="margin-top: 0px; margin-bottom: 0px; padding: 1em 1em 1em 0px; max-width: 1000%; overflow-x: auto; white-space: normal; -webkit-box-flex: 1; flex: 1 1 0%; color: rgb(51, 51, 51); font-size: 14px; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; word-wrap: break-word !important;"><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;"><br style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;" /></span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">    Dim cnn As Object</span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">    <span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">Set</span> cnn = CreateObject(<span class="code-snippet__string" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(221, 17, 68);">&quot;adodb.connection&quot;</span>)</span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">    cnn.Open <span class="code-snippet__string" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(221, 17, 68);">&quot;provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=&quot;</span> &amp; ThisWorkbook.FullName</span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">    <span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">If</span> cnn.State = <span class="code-snippet__number" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(14, 156, 229);">1</span> <span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">Then</span></span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">        MsgBox <span class="code-snippet__string" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(221, 17, 68);">&quot;连接成功!&quot;</span> &amp; vbCrLf &amp; <span class="code-snippet__string" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(221, 17, 68);">&quot;ADO版本为：&quot;</span> &amp; cnn.Version &amp; vbCrLf &amp; <span class="code-snippet__string" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(221, 17, 68);">&quot;Connection对象提供者名称：&quot;</span> &amp; cnn.provider</span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">        cnn.Close</span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">        <span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">Set</span> cnn = <span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">Nothing</span></span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">    <span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">Else</span></span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">        MsgBox <span class="code-snippet__string" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(221, 17, 68);">&quot;数据库连接失败&quot;</span></span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;">    <span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">End</span> <span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">If</span></span></code><code style="margin: 0px; padding: 0px; max-width: 1000%; text-align: left; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;"><span class="code-snippet__keyword" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(202, 125, 55);">End</span> Sub <br /></span><span class="code-snippet_outer" style="margin: 0px; padding: 0px; max-width: 1000%; box-sizing: border-box !important; word-wrap: break-word !important;"><div>&nbsp;</div><div><br />来源：https://mp.weixin.qq.com/s?__biz=MzI0MTAxNTc5NA==&amp;mid=2468634602&amp;idx=4&amp;sn=4a53cea4ba4a85ae828b17a8f42f693e&amp;chksm=ffc2f177c8b578618aee2e7408bac59c76470c9211969933e3617f91e5e79373d469eebf7927&amp;scene=21#wechat_redirect</div><div>&nbsp;</div><div>以下代码兼顾了03及各高级版本Excel的情况：</div><div>&nbsp;</div><div>Sub Mycnn3()</div><div>&nbsp; &nbsp; Dim cnn As Object</div><div>&nbsp; &nbsp; Dim strPath As String</div><div>&nbsp; &nbsp; Dim str_cnn As String</div><div>&nbsp; &nbsp; Set cnn = CreateObject(&quot;adodb.connection&quot;)</div><div>&nbsp; &nbsp; strPath = ThisWorkbook.FullName</div><div>&nbsp; &nbsp; If Application.Version &lt; 12 Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; str_cnn = &quot;Provider=Microsoft.jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=&quot; &amp; strPath</div><div>&nbsp; &nbsp; Else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; str_cnn = &quot;Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=&quot; &amp; strPath</div><div>&nbsp; &nbsp; End If</div><div>&nbsp; &nbsp; cnn.Open str_cnn</div><div>&nbsp; &nbsp; cnn.Close</div><div>&nbsp; &nbsp; Set cnn = Nothing</div><div>End sub</div><div>来源：https://mp.weixin.qq.com/s?__biz=MzI0MTAxNTc5NA==&amp;mid=2468634477&amp;idx=3&amp;sn=47e652209bab466e8bab3e27cd38a58d&amp;chksm=ffc2f1f0c8b578e6e7ea0fac79289ff858e82641dd740e45e3135644a895fd74a550061bdf99&amp;scene=21#wechat_redirect</div></span></code></pre>]]></description>
		</item>
		
			<item>
			<link>http://www.niaochao2008.com/20180311/article.asp?id=90</link>
			<title><![CDATA[学SQL in Excel教程合集]]></title>
			<author>shopsha2002@126.com(admin)</author>
			<category><![CDATA[特色代码]]></category>
			<pubDate>Sun,23 Feb 2020 17:42:47 +0800</pubDate>
			<guid>http://www.niaochao2008.com/20180311/default.asp?id=90</guid>
		<description><![CDATA[<p>&nbsp;</p>
<h2 class="rich_media_title" id="activity-name" style="margin: 0px 0px 14px; padding: 0px; font-weight: 400; font-size: 22px; line-height: 1.4; color: rgb(51, 51, 51); font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px;">学SQL in Excel教程合集</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="https://mp.weixin.qq.com/s/X5NbOIimYZ5jG0qU_mlWUg" target="_blank">https://mp.weixin.qq.com/s/X5NbOIimYZ5jG0qU_mlWUg</a></p>]]></description>
		</item>
		
</channel>
</rss>
