<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>VBA | You Look Too Cool</title>
	<atom:link href="https://stabucky.com/wp/archives/tag/vba/feed" rel="self" type="application/rss+xml" />
	<link>https://stabucky.com/wp</link>
	<description>ゆるくつくる stabuckyのブログ</description>
	<lastBuildDate>Sun, 23 Nov 2025 13:54:10 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://stabucky.com/wp/wp-content/uploads/2024/05/cropped-stabucky-32x32.png</url>
	<title>VBA | You Look Too Cool</title>
	<link>https://stabucky.com/wp</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>VBAでカレントディレクトリを変更する方法</title>
		<link>https://stabucky.com/wp/archives/16564</link>
					<comments>https://stabucky.com/wp/archives/16564#respond</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Fri, 08 Mar 2024 10:26:58 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=16564</guid>

					<description><![CDATA[ファイルを出力するExcelのマクロを実行するとそのファイルがどこに行ったか分からなくなることがあります。 カレントディレクトリに出力されるのですが、そもそもカレントディレクトリがどこなのか分かりません。 ファイルのある [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>ファイルを出力するExcelのマクロを実行するとそのファイルがどこに行ったか分からなくなることがあります。<br />
カレントディレクトリに出力されるのですが、そもそもカレントディレクトリがどこなのか分かりません。<br />
ファイルのある場所をカレントディレクトリに変更してしまえば問題ないはずです。<span id="more-16564"></span></p>
<p>Excel VBAでは、カレントディレクトリを変更するための特定のコマンドが用意されています。<br />
これは、ファイルやディレクトリを操作する際に非常に便利です。<br />
その使用例を示します。</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">' カレントディレクトリをファイルのある場所に変更<br />
ChDrive Left(ThisWorkbook.Path, 1)<br />
ChDir ThisWorkbook.Path</div></div>
<p>カレントディレクトリを現在のワークブックのある場所に変更します。</p>
<p>ChDrive コマンドは、ドライブを変更します。<br />
Left(ThisWorkbook.Path, 1) は、ワークブックのパスから最初の文字（つまり、ドライブの文字）を取得します。</p>
<p>ChDir コマンドは、ディレクトリを変更します。<br />
ThisWorkbook.Path は、現在のワークブックのフルパスを返します。</p>
<p>これにより、後続のファイル操作コマンドがワークブックと同じ場所を参照するようになります。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/16564/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>選択範囲の全角半角を変換するマクロ</title>
		<link>https://stabucky.com/wp/archives/15605</link>
					<comments>https://stabucky.com/wp/archives/15605#respond</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Thu, 23 Feb 2023 09:57:33 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=15605</guid>

					<description><![CDATA[Excelのセルを選択した範囲について英字や数字の全角と半角を相互に変換するマクロを作りました。 Sub 選択範囲の全角半角を変換() &#160; Dim c As Object &#160; res = InputB [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Excelのセルを選択した範囲について英字や数字の全角と半角を相互に変換するマクロを作りました。<span id="more-15605"></span></p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Sub 選択範囲の全角半角を変換()<br />
&nbsp; Dim c As Object<br />
&nbsp; res = InputBox(&quot;1:英字を全角から半角 2:英字を半角から全角 3:数字を全角から半角 4:数字を半角から全角&quot;, &quot;全角半角変換&quot;, &quot;1&quot;)<br />
&nbsp; If res = &quot;1&quot; Then<br />
&nbsp; &nbsp; For Each c In Selection<br />
&nbsp; &nbsp; &nbsp; c.Value = alphabet_zen2han(c.Value)<br />
&nbsp; &nbsp; Next c<br />
&nbsp; ElseIf res = &quot;2&quot; Then<br />
&nbsp; &nbsp; For Each c In Selection<br />
&nbsp; &nbsp; &nbsp; c.Value = alphabet_han2zen(c.Value)<br />
&nbsp; &nbsp; Next c<br />
&nbsp; ElseIf res = &quot;3&quot; Then<br />
&nbsp; &nbsp; For Each c In Selection<br />
&nbsp; &nbsp; &nbsp; c.Value = number_zen2han(c.Value)<br />
&nbsp; &nbsp; Next c<br />
&nbsp; ElseIf res = &quot;4&quot; Then<br />
&nbsp; &nbsp; For Each c In Selection<br />
&nbsp; &nbsp; &nbsp; c.Value = number_han2zen(c.Value)<br />
&nbsp; &nbsp; Next c<br />
&nbsp; End If<br />
End Sub<br />
<br />
Function alphabet_zen2han(moto)<br />
&nbsp; For i = 1 To Len(moto)<br />
&nbsp; &nbsp; If Mid(moto, i, 1) Like &quot;[Ａ-Ｚａ-ｚ]&quot; Then<br />
&nbsp; &nbsp; &nbsp; Mid(moto, i, 1) = StrConv(Mid(moto, i, 1), vbNarrow)<br />
&nbsp; &nbsp; End If<br />
&nbsp; Next i<br />
&nbsp; alphabet_zen2han = moto<br />
End Function<br />
<br />
Function alphabet_han2zen(moto)<br />
&nbsp; For i = 1 To Len(moto)<br />
&nbsp; &nbsp; If Mid(moto, i, 1) Like &quot;[A-Za-z]&quot; Then<br />
&nbsp; &nbsp; &nbsp; Mid(moto, i, 1) = StrConv(Mid(moto, i, 1), vbWide)<br />
&nbsp; &nbsp; End If<br />
&nbsp; Next i<br />
&nbsp; alphabet_han2zen = moto<br />
End Function<br />
<br />
Function number_zen2han(moto)<br />
&nbsp; For i = 1 To Len(moto)<br />
&nbsp; &nbsp; If Mid(moto, i, 1) Like &quot;[０-９]&quot; Then<br />
&nbsp; &nbsp; &nbsp; Mid(moto, i, 1) = StrConv(Mid(moto, i, 1), vbNarrow)<br />
&nbsp; &nbsp; End If<br />
&nbsp; Next i<br />
&nbsp; number_zen2han = moto<br />
End Function<br />
<br />
Function number_han2zen(moto)<br />
&nbsp; For i = 1 To Len(moto)<br />
&nbsp; &nbsp; If Mid(moto, i, 1) Like &quot;[0-9]&quot; Then<br />
&nbsp; &nbsp; &nbsp; Mid(moto, i, 1) = StrConv(Mid(moto, i, 1), vbWide)<br />
&nbsp; &nbsp; End If<br />
&nbsp; Next i<br />
&nbsp; number_han2zen = moto<br />
End Function</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/15605/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>文字列の類似度を計算するレーベンシュタイン距離をPython、VBAで実装</title>
		<link>https://stabucky.com/wp/archives/15338</link>
					<comments>https://stabucky.com/wp/archives/15338#respond</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Sat, 12 Nov 2022 06:39:03 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[類似度]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=15338</guid>

					<description><![CDATA[目次 レーベンシュタイン距離とはPythonVBA レーベンシュタイン距離とは 文字列が二つあったとき、これらがどれほど類似しているかを知るための指標の一つがレーベンシュタイン距離です。 厳密に言えば「どれほど相違してい [&#8230;]]]></description>
										<content:encoded><![CDATA[
  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-6" checked><label class="toc-title" for="toc-checkbox-6">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">レーベンシュタイン距離とは</a></li><li><a href="#toc2" tabindex="0">Python</a></li><li><a href="#toc3" tabindex="0">VBA</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">レーベンシュタイン距離とは</span></h2>
<p>文字列が二つあったとき、これらがどれほど類似しているかを知るための指標の一つがレーベンシュタイン距離です。<br />
厳密に言えば「どれほど相違しているかを示す指標」です。</p>

<a rel="noopener" href="https://ja.wikipedia.org/wiki/%E3%83%AC%E3%83%BC%E3%83%99%E3%83%B3%E3%82%B7%E3%83%A5%E3%82%BF%E3%82%A4%E3%83%B3%E8%B7%9D%E9%9B%A2" title="レーベンシュタイン距離 - Wikipedia" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img decoding="async" src="https://s.wordpress.com/mshots/v1/https%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%25E3%2583%25AC%25E3%2583%25BC%25E3%2583%2599%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A5%25E3%2582%25BF%25E3%2582%25A4%25E3%2583%25B3%25E8%25B7%259D%25E9%259B%25A2?w=160&#038;h=90" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">レーベンシュタイン距離 - Wikipedia</div><div class="blogcard-snippet external-blogcard-snippet"></div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img decoding="async" src="https://www.google.com/s2/favicons?domain=https://ja.wikipedia.org/wiki/%E3%83%AC%E3%83%BC%E3%83%99%E3%83%B3%E3%82%B7%E3%83%A5%E3%82%BF%E3%82%A4%E3%83%B3%E8%B7%9D%E9%9B%A2" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">ja.wikipedia.org</div></div></div></div></a>
<p>ここにレーベンシュタイン距離を求める方法が擬似コードで示されているのでPythonとVBAで書いてみました。<br />
レーベンシュタイン距離は相違を示す指標なので、二つの文字列の長い方の長さで割り1から減じた数値のほうが使いやすいです。<br />
同じ文字列は1.0になります。<br />
類似度を表す関数をsimirality、レーベンシュタイン距離を求める関数をlevenshteinとしました。</p>
<h2><span id="toc2">Python</span></h2>
<div class="codecolorer-container python dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #ff7700;font-weight:bold;">def</span> similarity<span style="color: black;">&#40;</span>str0<span style="color: #66cc66;">,</span> str1<span style="color: black;">&#41;</span>:<br />
&nbsp; ld <span style="color: #66cc66;">=</span> levenshtein<span style="color: black;">&#40;</span>str0<span style="color: #66cc66;">,</span> str1<span style="color: black;">&#41;</span><br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span> - ld / <span style="color: #008000;">max</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>str0<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>str1<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> levenshtein<span style="color: black;">&#40;</span>str0<span style="color: #66cc66;">,</span> str1<span style="color: black;">&#41;</span>:<br />
&nbsp; len_str0 <span style="color: #66cc66;">=</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>str0<span style="color: black;">&#41;</span><br />
&nbsp; len_str1 <span style="color: #66cc66;">=</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>str1<span style="color: black;">&#41;</span><br />
&nbsp; d <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>len_str1 + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>len_str0 + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>len_str0 + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; d<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> i<br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>len_str1 + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; d<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> j<br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>len_str0<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>len_str1<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; cost <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">if</span> str0<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: #66cc66;">==</span> str1<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; d<span style="color: black;">&#91;</span>i + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>j + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #008000;">min</span><span style="color: black;">&#40;</span>d<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>j + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #ff4500;">1</span><span style="color: #66cc66;">,</span> d<span style="color: black;">&#91;</span>i + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> d<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span> + cost<span style="color: black;">&#41;</span><br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> d<span style="color: black;">&#91;</span>len_str0<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>len_str1<span style="color: black;">&#93;</span></div></div>
<h2><span id="toc3">VBA</span></h2>
<div class="codecolorer-container vb dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #E56717; font-weight: bold;">Function</span> similarity(str1, str2)<br />
&nbsp; ld = levenshteinDistance(str1, str2)<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Len(str1) &gt; Len(str2) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; str_len = Len(str1)<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; str_len = Len(str2)<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; similarity = 1 - ld / str_len<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span><br />
<br />
<span style="color: #E56717; font-weight: bold;">Function</span> levenshteinDistance(str1, str2)<br />
&nbsp; x = Len(str1)<br />
&nbsp; y = Len(str2)<br />
&nbsp; <span style="color: #151B8D; font-weight: bold;">ReDim</span> d(x, y)<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = 0 <span style="color: #8D38C9; font-weight: bold;">To</span> x<br />
&nbsp; &nbsp; d(i, 0) = i<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = 0 <span style="color: #8D38C9; font-weight: bold;">To</span> y<br />
&nbsp; &nbsp; d(0, j) = j<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> x<br />
&nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> y<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Mid(str1, i, 1) = Mid(str2, j, 1) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cost = 0<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cost = 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; temp = d(i - 1, j) + 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> temp &gt; d(i, j - 1) + 1 <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; temp = d(i, j - 1) + 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> temp &gt; d(i - 1, j - 1) + cost <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; temp = d(i - 1, j - 1) + cost<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; d(i, j) = temp<br />
&nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; levenshteinDistance = d(x, y)<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/15338/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Excelを閉じる前に確認するマクロ</title>
		<link>https://stabucky.com/wp/archives/15234</link>
					<comments>https://stabucky.com/wp/archives/15234#respond</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Tue, 20 Sep 2022 10:28:07 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=15234</guid>

					<description><![CDATA[以前作りその後使わなくなったマクロがあるのでメモとして残します。 Private Sub Workbook_BeforeClose(Cancel As Boolean) &#160; &#160; res = MsgBo [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>以前作りその後使わなくなったマクロがあるのでメモとして残します。<span id="more-15234"></span></p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Private Sub Workbook_BeforeClose(Cancel As Boolean)<br />
&nbsp; &nbsp; res = MsgBox(&quot;開いたままにするか？（閉じるならば「いいえ」）&quot;, vbYesNo)<br />
&nbsp; &nbsp; If res = vbYes Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; Cancel = True '&quot;Cancel = True&quot;ならば閉じない。<br />
&nbsp; &nbsp; End If<br />
End Sub</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/15234/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Wordで色を変えて置換するマクロ</title>
		<link>https://stabucky.com/wp/archives/14428</link>
					<comments>https://stabucky.com/wp/archives/14428#respond</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Mon, 06 Sep 2021 07:01:41 +0000</pubDate>
				<category><![CDATA[Word]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[置換]]></category>
		<category><![CDATA[色]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=14428</guid>

					<description><![CDATA[Wordは文字列の置換をするときに書式を設定することができるので文字の色を変えることもできます。 これをマクロに応用してみました。 Sub テスト() &#160; Call 色を変えて置換(&#34;エディタ&#038;quo [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Wordは文字列の置換をするときに書式を設定することができるので文字の色を変えることもできます。<br />
これをマクロに応用してみました。<span id="more-14428"></span></p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Sub テスト()<br />
&nbsp; Call 色を変えて置換(&quot;エディタ&quot;, wdColorRed, &quot;エディタ&quot;, wdColorBlue)<br />
End Sub<br />
<br />
Function 色を変えて置換(moto_text, moto_color, saki_text, saki_color)<br />
&nbsp; Set myrange = ActiveDocument.Range(Start:=0, End:=0)<br />
&nbsp; With myrange.Find<br />
&nbsp; &nbsp; .ClearFormatting<br />
&nbsp; &nbsp; .Font.Color = moto_color<br />
&nbsp; &nbsp; .Replacement.ClearFormatting<br />
&nbsp; &nbsp; .Replacement.Font.Color = saki_color<br />
&nbsp; &nbsp; .Text = moto_text<br />
&nbsp; &nbsp; .Replacement.Text = saki_text<br />
&nbsp; &nbsp; .Execute Replace:=wdReplaceAll<br />
&nbsp; End With<br />
End Function</div></div>
<p>「テスト」が実行用のコードです。</p>
<p>「色を変えて置換」が置換する部分です。<br />
moto_text, moto_color, saki_text, saki_colorにそれぞれ検索文字列、置換元の色、置換文字列、置換先の色をセットします。</p>
<p>色はwdColorRedなどのVBAの定数で表します。<br />
内容は<a rel="noopener" href="https://docs.microsoft.com/ja-jp/office/vba/api/word.wdcolor" target="_blank">WdColor 列挙 (Word) | Microsoft Docs</a>にあります。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/14428/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ハイパーリンクがあるセルに網かけをするマクロ</title>
		<link>https://stabucky.com/wp/archives/13859</link>
					<comments>https://stabucky.com/wp/archives/13859#respond</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Fri, 05 Feb 2021 02:06:54 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[ハイパーリンク]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=13859</guid>

					<description><![CDATA[以前、ハイパーリンクの有無を判定するユーザー定義関数を紹介しました。 今回は同じ仕組みを使い、ハイパーリンクがあるセルに網かけをするマクロを作りました。 色は「vbYellow」の所で設定します。 カラー定数 &#124; Mic [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>以前、<a href="https://stabucky.com/wp/archives/13837">ハイパーリンクの有無を判定するユーザー定義関数</a>を紹介しました。<br />
今回は同じ仕組みを使い、ハイパーリンクがあるセルに網かけをするマクロを作りました。<span id="more-13859"></span></p>
<p>色は「vbYellow」の所で設定します。<br />
<a rel="noopener" href="https://docs.microsoft.com/ja-jp/office/vba/language/reference/user-interface-help/color-constants" target="_blank">カラー定数 | Microsoft Docs</a></p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Sub 選択範囲のハイパーリンクがあるセルに網かけ()<br />
&nbsp; Dim c As Object<br />
&nbsp; For Each c In Selection<br />
&nbsp; &nbsp; If c.Hyperlinks.Count &gt; 0 Then<br />
&nbsp; &nbsp; &nbsp; With c.Interior<br />
&nbsp; &nbsp; &nbsp; &nbsp; .Pattern = xlSolid<br />
&nbsp; &nbsp; &nbsp; &nbsp; .Color = vbYellow<br />
&nbsp; &nbsp; &nbsp; End With<br />
&nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; With c.Interior<br />
&nbsp; &nbsp; &nbsp; &nbsp; .Pattern = xlNone<br />
&nbsp; &nbsp; &nbsp; End With<br />
&nbsp; &nbsp; End If<br />
&nbsp; Next c<br />
End Sub</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/13859/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ハイパーリンクの有無を判定するユーザー定義関数</title>
		<link>https://stabucky.com/wp/archives/13837</link>
					<comments>https://stabucky.com/wp/archives/13837#comments</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Fri, 29 Jan 2021 09:36:07 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[ハイパーリンク]]></category>
		<category><![CDATA[ユーザー定義関数]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=13837</guid>

					<description><![CDATA[Excelでそのセルにハイパーリンクがあるか否かを判定するユーザー定義関数を作りました。 「範囲.Hyperlinks.Count」で指定した範囲内のハイパーリンクの数を取得できます。 これを使っています。 Functi [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Excelでそのセルにハイパーリンクがあるか否かを判定するユーザー定義関数を作りました。<br />
「範囲.Hyperlinks.Count」で指定した範囲内のハイパーリンクの数を取得できます。<br />
これを使っています。<span id="more-13837"></span></p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Function ISHYPERLINK(myrange As Range)<br />
&nbsp; If myrange.Hyperlinks.Count &gt; 0 Then<br />
&nbsp; &nbsp; ISHYPERLINK = True<br />
&nbsp; Else<br />
&nbsp; &nbsp; ISHYPERLINK = False<br />
&nbsp; End If<br />
End Function</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/13837/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>複数のWord文書に対して文字列リストを元に連続して置換するマクロ</title>
		<link>https://stabucky.com/wp/archives/13067</link>
					<comments>https://stabucky.com/wp/archives/13067#comments</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Thu, 21 May 2020 22:07:40 +0000</pubDate>
				<category><![CDATA[Word]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[置換]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=13067</guid>

					<description><![CDATA[以前、Wordに関する次の二つのマクロを紹介しました。 Wordで文字列リストを元に連続して置換するマクロ 複数のWord文書に対して文字列置換 今般、「これらを組み合わせたい」という要望をいただきましたので、試してみま [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>以前、Wordに関する次の二つのマクロを紹介しました。<br />
<a href="https://stabucky.com/wp/archives/2309">Wordで文字列リストを元に連続して置換するマクロ</a><br />
<a href="https://stabucky.com/wp/archives/7897">複数のWord文書に対して文字列置換</a><br />
今般、「これらを組み合わせたい」という要望をいただきましたので、試してみました。<span id="more-13067"></span></p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-16" checked><label class="toc-title" for="toc-checkbox-16">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">準備</a></li><li><a href="#toc2" tabindex="0">リスト</a></li><li><a href="#toc3" tabindex="0">コード</a></li><li><a href="#toc4" tabindex="0">下階層対応版</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">準備</span></h2>
<p>適当なフォルダに文字列置換したいWordファイルを保存します。これを「対象フォルダ」と呼びます。<br />
確認せずに一気に置換して上書き保存しますので、これらのファイルは<strong>必ずバックアップ</strong>を取っておいてください。<br />
利用に関しては自己責任でお願いします。</p>
<h2><span id="toc2">リスト</span></h2>
<p>マクロ実行用のWordファイルを準備します。「対象フォルダ」とは別のフォルダに保存します。<br />
本文に次のようなリストを書いておきます。<br />
置換前と置換後の文字列を並べ、セミコロン(;)で区切ります。</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">エディター;エディタ<br />
プリンター;プリンタ<br />
サーバー;サーバ</div></div>
<h2><span id="toc3">コード</span></h2>
<p>次のコードを使います。使い方が分からない場合は「<a href="https://stabucky.com/wp/archives/13029" target="_blank">マクロを書く方法</a>」を参照してください。<br />
マクロを実行するとフォルダを選ぶダイアログが出ます。「対象フォルダ」を選択してください。<br />
選択するとフォルダ内のファイルが順に開き、リストに従って次々に置換が実行され、上書き保存されます。</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;height:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Sub 複数文書連続処理_リストを元に置換()<br />
&nbsp; Dim mae(100)<br />
&nbsp; Dim ato(100)<br />
&nbsp; <br />
&nbsp; '置換用配列<br />
&nbsp; Set paras = ActiveDocument.Paragraphs<br />
&nbsp; x = 0<br />
&nbsp; For i = 1 To paras.Count<br />
&nbsp; &nbsp; thisline = paras(i).Range.Text<br />
&nbsp; &nbsp; parts = Split(thisline, &quot;;&quot;)<br />
&nbsp; &nbsp; If UBound(parts) &gt; 0 Then<br />
&nbsp; &nbsp; &nbsp; mae(x) = parts(0)<br />
&nbsp; &nbsp; &nbsp; ato(x) = Replace(parts(1), Chr(13), &quot;&quot;)<br />
&nbsp; &nbsp; &nbsp; x = x + 1<br />
&nbsp; &nbsp; End If<br />
&nbsp; Next i<br />
&nbsp; <br />
&nbsp; 'フォルダの選択<br />
&nbsp; With Application.FileDialog(msoFileDialogFolderPicker)<br />
&nbsp; &nbsp; .Title = &quot;フォルダを選択&quot;<br />
&nbsp; &nbsp; .AllowMultiSelect = False<br />
&nbsp; &nbsp; If .Show = -1 Then<br />
&nbsp; &nbsp; &nbsp; mypath = .SelectedItems(1) &amp; &quot;\&quot;<br />
&nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; MsgBox &quot;終了します。&quot;<br />
&nbsp; &nbsp; &nbsp; Exit Sub<br />
&nbsp; &nbsp; End If<br />
&nbsp; End With<br />
&nbsp; <br />
&nbsp; 'Word文書に対する処理<br />
&nbsp; myfile = Dir(mypath &amp; &quot;*.doc*&quot;)<br />
&nbsp; Do While myfile &lt;&gt; &quot;&quot;<br />
&nbsp; &nbsp; Documents.Open FileName:=mypath &amp; myfile<br />
&nbsp; &nbsp; For i = 0 To x - 1<br />
&nbsp; &nbsp; &nbsp; Call 文書全体を置換(mae(i), ato(i))<br />
&nbsp; &nbsp; Next i<br />
&nbsp; &nbsp; ActiveWindow.Close SaveChanges:=wdSaveChanges<br />
&nbsp; &nbsp; myfile = Dir<br />
&nbsp; Loop<br />
End Sub<br />
Function 文書全体を置換(mae, ato)<br />
&nbsp; Set myrange = ActiveDocument.Range(Start:=0, End:=0)<br />
&nbsp; With myrange.Find<br />
&nbsp; &nbsp; .ClearFormatting<br />
&nbsp; &nbsp; .Text = mae<br />
&nbsp; &nbsp; With .Replacement<br />
&nbsp; &nbsp; &nbsp; .ClearFormatting<br />
&nbsp; &nbsp; &nbsp; .Text = ato<br />
&nbsp; &nbsp; End With<br />
&nbsp; &nbsp; .Execute Replace:=wdReplaceAll<br />
&nbsp; End With<br />
End Function</div></div>
<h2><span id="toc4">下階層対応版</span></h2>
<p>「<a href="https://stabucky.com/wp/archives/7253">下の階層を含めたファイル一覧を作成するマクロ</a>」を参考にして、指定したフォルダの配下のフォルダに対応したバージョンを作りました。<br />
宣言以降、全てのコードを下のとおり、まとめました。全てをコピー＆ペーストするだけで使えます。</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;height:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Dim all_files(9999, 1) As String<br />
Dim last_index<br />
<br />
Sub 複数文書連続処理_リストを元に置換()<br />
&nbsp; Dim mae(100)<br />
&nbsp; Dim ato(100)<br />
&nbsp; <br />
&nbsp; '置換用配列<br />
&nbsp; Set paras = ActiveDocument.Paragraphs<br />
&nbsp; x = 0<br />
&nbsp; For i = 1 To paras.Count<br />
&nbsp; &nbsp; thisline = paras(i).Range.Text<br />
&nbsp; &nbsp; parts = Split(thisline, &quot;;&quot;)<br />
&nbsp; &nbsp; If UBound(parts) &gt; 0 Then<br />
&nbsp; &nbsp; &nbsp; mae(x) = parts(0)<br />
&nbsp; &nbsp; &nbsp; ato(x) = Replace(parts(1), Chr(13), &quot;&quot;)<br />
&nbsp; &nbsp; &nbsp; x = x + 1<br />
&nbsp; &nbsp; End If<br />
&nbsp; Next i<br />
&nbsp; <br />
&nbsp; 'フォルダの選択<br />
&nbsp; With Application.FileDialog(msoFileDialogFolderPicker)<br />
&nbsp; &nbsp; .Title = &quot;フォルダを選択&quot;<br />
&nbsp; &nbsp; .AllowMultiSelect = False<br />
&nbsp; &nbsp; If .Show = -1 Then<br />
&nbsp; &nbsp; &nbsp; mypath = .SelectedItems(1) &amp; &quot;\&quot;<br />
&nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; MsgBox &quot;終了します。&quot;<br />
&nbsp; &nbsp; &nbsp; Exit Sub<br />
&nbsp; &nbsp; End If<br />
&nbsp; End With<br />
&nbsp; <br />
&nbsp; '全てのファイル名を取得（下階層を含む）<br />
&nbsp; Call get_files(mypath)<br />
&nbsp; <br />
&nbsp; 'Word文書に対する処理<br />
&nbsp; j = 0<br />
&nbsp; Do<br />
&nbsp; &nbsp; Documents.Open FileName:=all_files(j, 1) &amp; all_files(j, 0)<br />
&nbsp; &nbsp; For i = 0 To x - 1<br />
&nbsp; &nbsp; &nbsp; Call 文書全体を置換(mae(i), ato(i))<br />
&nbsp; &nbsp; Next i<br />
&nbsp; &nbsp; ActiveWindow.Close SaveChanges:=wdSaveChanges<br />
&nbsp; &nbsp; j = j + 1<br />
&nbsp; Loop Until all_files(j, 0) = &quot;&quot;<br />
End Sub<br />
Function 文書全体を置換(mae, ato)<br />
&nbsp; Set myrange = ActiveDocument.Range(Start:=0, End:=0)<br />
&nbsp; With myrange.Find<br />
&nbsp; &nbsp; .ClearFormatting<br />
&nbsp; &nbsp; .Text = mae<br />
&nbsp; &nbsp; With .Replacement<br />
&nbsp; &nbsp; &nbsp; .ClearFormatting<br />
&nbsp; &nbsp; &nbsp; .Text = ato<br />
&nbsp; &nbsp; End With<br />
&nbsp; &nbsp; .Execute Replace:=wdReplaceAll<br />
&nbsp; End With<br />
End Function<br />
Function get_files(my_path)<br />
&nbsp; 'Word用<br />
&nbsp; '指定したフォルダにある全てのファイル名(パス付)を取得する。<br />
&nbsp; Dim this_file(999) As String<br />
&nbsp; Dim this_path As String<br />
&nbsp; Dim i As Long<br />
&nbsp; Dim j As Long<br />
&nbsp; this_file(0) = Dir(my_path, vbDirectory)<br />
&nbsp; i = 0<br />
&nbsp; Do<br />
&nbsp; &nbsp; i = i + 1<br />
&nbsp; &nbsp; this_file(i) = Dir<br />
&nbsp; Loop Until this_file(i) = &quot;&quot;<br />
&nbsp; For j = 0 To i - 1<br />
&nbsp; &nbsp; If this_file(j) &lt;&gt; &quot;.&quot; And this_file(j) &lt;&gt; &quot;..&quot; Then<br />
&nbsp; &nbsp; &nbsp; If GetAttr(my_path &amp; this_file(j)) = vbDirectory Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; Call get_files(my_path &amp; this_file(j) &amp; &quot;\&quot;)<br />
&nbsp; &nbsp; &nbsp; ElseIf InStr(this_file(j), &quot;.doc&quot;) &gt; 0 Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; all_files(last_index, 0) = this_file(j)<br />
&nbsp; &nbsp; &nbsp; &nbsp; all_files(last_index, 1) = my_path<br />
&nbsp; &nbsp; &nbsp; &nbsp; last_index = last_index + 1<br />
&nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; End If<br />
&nbsp; Next j<br />
End Function</div></div>
<p>2020年7月18日追記<br />
「下階層のファイルにも対応させたい」という要望をいただきましたので、試してみました。</p>
<p>2022年5月24日追記<br />
Word文書以外が保存されている場合でも対応できるように修正しました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/13067/feed</wfw:commentRss>
			<slash:comments>30</slash:comments>
		
		
			</item>
		<item>
		<title>マクロを書く方法</title>
		<link>https://stabucky.com/wp/archives/13029</link>
					<comments>https://stabucky.com/wp/archives/13029#comments</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Sat, 09 May 2020 09:29:32 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=13029</guid>

					<description><![CDATA[ExcelでVBAが使えるようになったのは5.0からだと思います。このときVBE(Microsoft Visual Basic for Applications)が使えるようになりました。 最近、365を使ってみましたが [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>ExcelでVBAが使えるようになったのは5.0からだと思います。このときVBE(Microsoft Visual Basic for Applications)が使えるようになりました。<br />
最近、365を使ってみましたが、使い勝手が同じでした。<br />
Excelのマクロ(VBA)の良いところは、基本的な部分については古いコードがそのまま使えるところです。</p>
<p>マクロを書く方法は次のとおりです。<br />
ここではExcelの場合を紹介しますが、Wordの場合も同様です。<span id="more-13029"></span></p>
<p>エクセルを開いた状態でAlt+F11を押します(Altキーを押しながらF11キーを押します)。※ここではファイル名をvba_test.xlsmとします。<br />
エディタ(Microsoft Visual Basic for Applications)が開きます。</p>
<p><img fetchpriority="high" decoding="async" src="https://stabucky.com/wp/wp-content/uploads/2020/05/vbe1.png" alt="" width="273" height="249" class="img-responsive" /></p>
<p>左側のVBAProjectを右クリックして、 挿入 &#8211; 標準モジュール を選択します。</p>
<p><img loading="lazy" decoding="async" src="https://stabucky.com/wp/wp-content/uploads/2020/05/vbe2.png" alt="" width="548" height="360" class="img-responsive" /></p>
<p>標準モジュールの「Module1」として右側にコードが開きます。<br />
ここにコードを書きます。</p>
<p><img loading="lazy" decoding="async" src="https://stabucky.com/wp/wp-content/uploads/2020/05/vbe3.png" alt="" width="808" height="525" class="img-responsive" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/13029/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>XLOOKUPをVBAで再現</title>
		<link>https://stabucky.com/wp/archives/12633</link>
					<comments>https://stabucky.com/wp/archives/12633#respond</comments>
		
		<dc:creator><![CDATA[stabucky]]></dc:creator>
		<pubDate>Wed, 16 Oct 2019 03:38:07 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[ユーザー定義関数]]></category>
		<guid isPermaLink="false">https://stabucky.com/wp/?p=12633</guid>

					<description><![CDATA[ExcelにはVLOOKUPという関数があります。これが使えるとExcel初心者は卒業と言える気がします。 「ある列を検索して同じ値がある行の別の列の値を返す」という、言葉にすると非常に分かりにくい関数ですが、使えるよう [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>ExcelにはVLOOKUPという関数があります。これが使えるとExcel初心者は卒業と言える気がします。<br />
「ある列を検索して同じ値がある行の別の列の値を返す」という、言葉にすると非常に分かりにくい関数ですが、使えるようになると非常に便利です。<br />
一方で使いにくい部分もあって、例えば検索列よりも返す値の列が右にある必要があります。また返す値の列は検索列から数えて何番目というのを指定する必要があります。<span id="more-12633"></span></p>
<p>そういう不満の声があったからか、マイクロソフトはXLOOKUPの提供を発表しました。</p>
<p><a rel="noopener" href="https://support.office.com/ja-jp/article/xlookup-%E9%96%A2%E6%95%B0-b7fd680e-6d10-43e6-84f9-88eae8bf5929" target="_blank">XLOOKUP 関数 &#8211; Office サポート</a></p>
<p>検索列と返す値の列をそれぞれ指定できるようです。<br />
また縦と横のどちらにも対応します。<br />
しかし、まだ製品版には搭載されていないようです。<br />
そこでVBAで再現してみました。</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Function XLOOKUP(検索値, 検索範囲, 戻り値の配列)<br />
&nbsp; ct_search = 0<br />
&nbsp; For Each value_search In 検索範囲<br />
&nbsp; &nbsp; If 検索値 = value_search Then<br />
&nbsp; &nbsp; &nbsp; Exit For<br />
&nbsp; &nbsp; End If<br />
&nbsp; &nbsp; ct_search = ct_search + 1<br />
&nbsp; Next<br />
&nbsp; <br />
&nbsp; ct_return = 0<br />
&nbsp; For Each value_return In 戻り値の配列<br />
&nbsp; &nbsp; If ct_search = ct_return Then<br />
&nbsp; &nbsp; &nbsp; Exit For<br />
&nbsp; &nbsp; End If<br />
&nbsp; &nbsp; ct_return = ct_return + 1<br />
&nbsp; Next<br />
&nbsp; XLOOKUP = value_return<br />
End Function</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://stabucky.com/wp/archives/12633/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
