<?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>You Look Too Cool &#187; VBA</title>
	<atom:link href="http://stabucky.com/wp/archives/tag/vba/feed" rel="self" type="application/rss+xml" />
	<link>http://stabucky.com/wp</link>
	<description>ゆるくつくる - stabuckyのブログ。</description>
	<lastBuildDate>Thu, 09 Feb 2012 22:24:25 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>複数ファイルパスワード操作</title>
		<link>http://stabucky.com/wp/archives/3845</link>
		<comments>http://stabucky.com/wp/archives/3845#comments</comments>
		<pubDate>Thu, 02 Feb 2012 09:52:17 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[パスワード]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3845</guid>
		<description><![CDATA[複数のExcelファイルに同じパスワードがセットされている場合に、それを一括して解除して保存するマクロです。 逆に一括してパスワードをセットすることもできます。 最初にダイアログでパターンを訊かれますので、解除ならば「はい」、セットならば「いいえ」を選択します。 次にダイアログでパスワードをセットします。 最後にファイルが保存されているフォルダを指定します。下位階層には対応していません。 「&#8221;\*.xls&#8221;」の部分を適宜、変更してください。 Excel2007で確認しました。 Sub 複数ファイルパスワード操作() &#160; &#160; Dim myfolder, myfn, myword, pwopen, pwclose &#160; &#160; Dim pattern &#160; &#160; '操作を選択 &#160; &#160; pattern = MsgBox(&#34;パスワード解除ならば「はい」、セットならば「いいえ」&#34;, vbYesNo) &#160; &#160; If pattern = vbCancel Then &#160; &#160; &#160; &#160; Exit Sub &#160; &#160; End If &#160; &#160; 'パスワードをセット &#160; &#160; myword = InputBox(&#34;パスワードを入力。&#34;) [...]]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3845/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>半角を全角に変換するユーザー定義関数</title>
		<link>http://stabucky.com/wp/archives/3839</link>
		<comments>http://stabucky.com/wp/archives/3839#comments</comments>
		<pubDate>Tue, 31 Jan 2012 10:10:53 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[変換]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3839</guid>
		<description><![CDATA[ExcelのVBAで半角を全角に変換するのはとても簡単です。 「StrConv」を使うといろいろな変換ができます。 引数に「vbWide」を指定すると半角を全角に変換します。 使用例は次の通りです。 Function han2zen(t) &#160; &#160; han2zen = StrConv(t, vbWide) End Function 次は半角カタカナを全角に変換する方法です。 カタカナは全角に変換するが、英数字は半角のままにしたい、というようなケースに使います。 Function han2zen_kana(t) &#160; &#160; Dim u, v As String &#160; &#160; Dim i As Long &#160; &#160; u = StrConv(t, vbWide) &#160; &#160; For i = 1 To Len(u) &#160; &#160; &#160; &#160; If Mid(u, i, 1) Like &#34;[!ァ-ヶー]&#34; [...]]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3839/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBAでワイルドカードを使う</title>
		<link>http://stabucky.com/wp/archives/3836</link>
		<comments>http://stabucky.com/wp/archives/3836#comments</comments>
		<pubDate>Tue, 31 Jan 2012 10:09:43 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3836</guid>
		<description><![CDATA[VBAでは「Like」を使ってワイルドカード的な使い方ができます。 If myword Like &#34;[a-z]&#34; Then 使い方は次の通りです。 【構文】 文字列 Like パターン 文字列がパターンに合致するとTrueを返します。 【パターン】 文字パターン 引数stringの中の一致する文字 ? 任意の1文字 * 任意の数の文字 # 任意の1文字の数字(0-9) [charlist] 文字リストcharlistに指定した文字の中の任意の1文字 [!charlist] 文字リストcharlistに指定した文字以外の任意の1文字 次にパターンに文字リストを使う場合の例を示します。 半角カタカナ [ｦ-ﾝ] 半角カタカナはコード順で「ｦｧｨｩ&#8230;ﾚﾛﾜﾝ」と並ぶので「[ｦ-ﾝ]」とします。 全角カタカナ [ァ-ヶー] 全角カタカナはコード順で「ァアィイ&#8230;ンヴヵヶ」と並ぶので「[ァ-ヶ]」とします。 ただし長音が含まれないので、これを含めるため「[ァ-ヶー]」とします。 全角ひらがな [ぁ-んー] 全角ひらがなはコード順で「ぁあぃい&#8230;ゐゑをん」と並ぶので「[ぁ-ん]」とします。 ただし長音が含まれないので、これを含めるため「[ぁ-んー]」とします。 半角英小文字 [a-z] 半角英大文字 [A-Z] 半角数字 # 「[0-9]」としてもよいのですが半角数字に関しては上述の通り「#」という記号が用意されています。]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3836/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>段組みをテキストで出力</title>
		<link>http://stabucky.com/wp/archives/3810</link>
		<comments>http://stabucky.com/wp/archives/3810#comments</comments>
		<pubDate>Wed, 25 Jan 2012 09:56:46 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Word]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[段組み]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3810</guid>
		<description><![CDATA[段組みを使ったWord文書を段組みの情報を残したままテキストで出力する方法です。 1段の場合は40文字、2段の場合は19文字で改行を挿入します。 段組みの段数は「段落.PageSetup.TextColumns.Count」で取得できます。 またセクション区切りの部分(文字コードが12)はそのまま出力すると表示がおかしくなるので判定して無視します。 関数「cut」は文字列に指定した文字数で改行を挿入します。 Sub 段組みをテキスト出力() &#160; &#160; '段数に応じて改行を追加しテキストファイルに出力する。 &#160; &#160; Const mojisu1 = 40 '段数が1のとき &#160; &#160; Const mojisu2 = 19 '段数が2のとき &#160; &#160; Const myfilename = &#34;d:\test.txt&#34; &#160; &#160; Dim danrakusu, dansu, mojisu, i &#160; &#160; Dim danraku &#160; &#160; Dim mytext &#160; &#160; '各段落の文字列と段数を取得し、段数に応じて改行を追加する。 &#160; &#160; danrakusu = ActiveDocument.Paragraphs.Count &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3810/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>複数ファイルシート一括検索</title>
		<link>http://stabucky.com/wp/archives/3606</link>
		<comments>http://stabucky.com/wp/archives/3606#comments</comments>
		<pubDate>Thu, 22 Dec 2011 11:53:31 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[検索]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3606</guid>
		<description><![CDATA[Windowsにはファイルの内容を検索する機能があります。 しかしExcelを検索する場合、どのファイルにあるかは表示されますが、どのシートにあるかは表示されません。 シートが多いと、そのファイルを開いてから、また検索する必要があります。 そこで、ある文字列について、特定のフォルダにある、すべてのExcelファイルのすべてのシートを検索し、どのシートにあるかを表示するマクロを考えました。 検索結果を表示するだけでなく、該当のセルにハイパーリンクを張るようになっています。 Excel2007で確認しました。 適当なExcelファイルを用意します。 シートの名前を「検索結果」とします。ここに検索結果が表示されます。 下に書かれているコード(3つの部分)を標準モジュールに貼り付けます(3つまとめて)。 マクロ「複数ファイルシート一括検索」を実行します。 検索したい文字列を入力します。 検索したいフォルダを指定します。 検索結果が表示されます。 「$A$1」という表示はセルを表し、リンクが張られています。クリックすると該当のファイルを開きジャンプします。 宣言 Const resultsn = &#34;検索結果&#34; Dim gyo As Long モジュールの先頭に書きます。 メイン Sub 複数ファイルシート一括検索() &#160; &#160; Dim myfolder, myfn, myword &#160; &#160; myword = InputBox(&#34;検索文字列を入力&#34;) &#160; &#160; With Application.FileDialog(msoFileDialogFolderPicker) &#160; &#160; &#160; &#160; .Title = &#34;フォルダを選択&#34; &#160; &#160; &#160; &#160; .AllowMultiSelect = [...]]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3606/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>日曜日を含まない経過日計算</title>
		<link>http://stabucky.com/wp/archives/3561</link>
		<comments>http://stabucky.com/wp/archives/3561#comments</comments>
		<pubDate>Sun, 11 Dec 2011 08:42:24 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[ユーザー定義関数]]></category>
		<category><![CDATA[日付]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3561</guid>
		<description><![CDATA[ある日からその日を含んでX日を経過した日をExcelで求めるには「始期となる日+X-1」とすればOKです。 では日曜日を含まないで計算するにはどうしたらよいでしょうか。 たとえば2011年12月8日(木)の7日経過した日は単純に計算すると14日(水)になります。 しかし日曜日を含まない場合、8日(木)の7日経過した日は15日(木)になります。 「木、金、土、月、火、水、木」と日曜日をとばすからです。 この日曜日をとばすという処理が面倒です。 最初に答を示すと次のとおりです。 =A2+INT((B2-1)/6*7)+IF(OR(WEEKDAY(A2)=1,WEEKDAY(A2)+MOD(B2-1,6)>7),1,0) セルA2 : 期始日 セルB2 : 日数(日曜日を含まない) ただし期始日が日曜日の場合は1日目は月曜日とします。 経過日数を計算するだけならば、日曜日を除く6日間が経過する度に、日曜日を含む7日間が経過しますので INT((B2-1)/6*7) となります。 しかし「端数」を考慮する必要があります。 例えば期始が木曜日で期末が火曜日の場合、期末の前の週の水曜日までは「日数/6*7」でピッタリ計算できますが、その後の前の週の木曜日から期末の火曜日までは調整が必要です。 つまり間に日曜日を挟む場合は経過日数が1日多くなります。 日 月 火 水 木 金 土 × × × × 始 ○ ○ □ ○ ○ ○ ○ ○ ○ □ ○ ○ ○ ◎ ◎ ◎ □ ◎ 末 × × × [...]]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3561/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>罫線の下端で改ページするマクロ</title>
		<link>http://stabucky.com/wp/archives/3541</link>
		<comments>http://stabucky.com/wp/archives/3541#comments</comments>
		<pubDate>Fri, 09 Dec 2011 12:38:23 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[改ページ]]></category>
		<category><![CDATA[罫線]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3541</guid>
		<description><![CDATA[Excelで罫線を使って表を作る場合は多いです。 一つのシートに複数の表を縦に作っていく場合、表の途中で改ページされると困ることがあります。 そこであらかじめ、それぞれの表の下端で改ページしておく、という方法が考えられます。 これを自動的に実行するマクロを作りました。 「表の下端」の定義ですが、次のように考えます。 「左と下に罫線がなく、その上のセルの左と下に罫線があるセル」 これをシートの上からチェックして該当するセルが見つかったら改ページを入れます。 Sub 罫線の下端で改ページ() &#160; &#160; Const c = 1 'チェックする列 &#160; &#160; For r = 2 To 1000 &#160; &#160; &#160; &#160; left0 = Cells(r - 1, c).Borders(7).LineStyle &#160; &#160; &#160; &#160; bottom0 = Cells(r - 1, c).Borders(9).LineStyle &#160; &#160; &#160; &#160; left1 = Cells(r, c).Borders(7).LineStyle &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3541/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>マクロでワイルドカードを使うときの注意</title>
		<link>http://stabucky.com/wp/archives/3458</link>
		<comments>http://stabucky.com/wp/archives/3458#comments</comments>
		<pubDate>Tue, 15 Nov 2011 14:20:12 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Word]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[置換]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3458</guid>
		<description><![CDATA[Wordのマクロでワイルドカードを使って検索、置換をしようとしたところエラーが出ました。 Sub replace_test() &#160; &#160; With Selection.Find &#160; &#160; &#160; &#160; .Text = &#34;あけまして*ございます&#34; &#160; &#160; &#160; &#160; .Replacement.Text = &#34;&#34; &#160; &#160; &#160; &#160; .MatchWildcards = True &#160; &#160; End With &#160; &#160; Selection.Find.Execute Replace:=wdReplaceAll End Sub エラーメッセージは次の通り。 MatchPhrase、MatchWildcards、MatchSoundsLike、MatchAllWordForms、MatchFuzzyパラメータは、同時にTrueに設定することができません。 Wordで検索、置換をするときはいろいろなオプションがあります。 文書を直に検索、置換するときは矛盾するオプションは選べないようになっていますが、マクロで使うときには正しく設定しないとエラーになります。 例えば、ワイルドカード検索とあいまい検索はどちらが優先するのか、はっきりしないのでエラーになるようです。 ところで、ここで登場した5個のオプションの意味は次の通りです。どれもTrueかFalseを設定します。 MatchPhrase 単語間のすべての空白文字および制御文字が無視されます。 MatchWildcards 検索する文字列にワイルドカードが含まれている場合、このプロパティの値は True です。 MatchSoundsLike True に設定すると、検索文字列に類似した単語が検索対象となります。 MatchAllWordForms True [...]]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3458/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBAで引数の数を可変にする</title>
		<link>http://stabucky.com/wp/archives/3431</link>
		<comments>http://stabucky.com/wp/archives/3431#comments</comments>
		<pubDate>Fri, 11 Nov 2011 21:44:03 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3431</guid>
		<description><![CDATA[VBAのユーザー定義関数で引数の数が一定でない場合があります。 Function kansu(a, b, c) このケースでは、a、b、cが引数です。引数の数は3個です。 Function kansu(a, b, c, d) このケースでは、a、b、c、dが引数です。引数の数は4個です。 このように、場合によって引数の数が違う場合のユーザー定義関数の作り方を示します。 ParamArrayを使う Function sample1(ParamArray arrs()) &#160; &#160; t = 0 &#160; &#160; For i = 0 To UBound(arrs) &#160; &#160; &#160; &#160; If IsNumeric(arrs(i)) Then &#160; &#160; &#160; &#160; &#160; &#160; t = t + arrs(i) &#160; &#160; &#160; &#160; End If &#160; [...]]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3431/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Word文書を開いたときに自動的にマクロを実行</title>
		<link>http://stabucky.com/wp/archives/3416</link>
		<comments>http://stabucky.com/wp/archives/3416#comments</comments>
		<pubDate>Thu, 10 Nov 2011 09:59:48 +0000</pubDate>
		<dc:creator>stabucky</dc:creator>
				<category><![CDATA[Word]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://stabucky.com/wp/?p=3416</guid>
		<description><![CDATA[Word文書を開いたときに自動的にマクロを実行する方法です。 ここでは文書を開いたときに「Hello!」というメッセージボックスを表示させます。 エディタを開く Wordで開発-コード-VisualBasicを選択しエディタ(MicrosoftVisualBasic)を開く。 イベントの設定 プロジェクトエクスプローラで編集したい「Project」を選択。 「Microsoft Word Objects」-「ThisDocument」をダブルクリック。メニューの表示-コードを選択してもよい。 表示されたコード(まだ何も入力されていない)の上部左側のオブジェクトボックスから「Document」を選択。 右側のプロシージャボックスから「Open」を選択。 コードに次の通り自動的に入力される。 Private Sub Document_Open() End Sub 次のように書き加える。 Private Sub Document_Open() &#160; &#160; MsgBox (&#34;Hello!&#34;) End Sub これで文書を保存し、再度、開くと、「Hello!」というメッセージボックスが表示されます。 最後の「MsgBox」のところを書き換えればいろいろなことができます。 例えば、差し込み文書で「WordBasic.MailMergeFindEntry」と書けば、文書を開いたときに、差し込み文書の「エントリの検索」ダイアログが表示されます。]]></description>
		<wfw:commentRss>http://stabucky.com/wp/archives/3416/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

