配列を使うのに役立つ4つの関数――Array、LBound、UBound、Splitの使い方:VBA/マクロ便利Tips 業務効率化に役立つVBA/マクロのさまざまなTipsをコード例を交えて紹介していきます。今回は、配列を返すArray、配列のインデックス番号の最小値/最大値を返すLBound/UBound、要素ごとに区切られた文字列から配列を作るSplitなどの使い方について解説。
MsgBoxで、どんなときに括弧を使うのかと、メッセージを改行する"改行コード"について、詳しい解説を動画で公開しています。ぜひ、こちらもご覧ください。Youtubeでは、ほかにもたくさんの動画を公開しています。チャンネル登録をお忘れなく! Office TANAKAチャンネル ■VBAのコードで、括弧はどんなときに使うのか 構文 引数promptは必ず指定します、ダイアログボックスに表示するメッセージを指定します。 引数buttonは省略可能です。ダイアログボックスに表示する、ボタンの種類やタイプなどを指定します。 引数titleは省略可能です。ダイアログボックスのタイトルバーに表示する文字列を指定します。 引数helpfileは省略可能です。ダイアログボックスの[ヘルプ]ボタンから開くヘルプファイルを指定します。引数helpfileを指定する場合は、引数contextも必ず指定しなけれ
配列は、いわば集合住宅のようなものです。1棟の建物に複数の世帯が同時に住むことが可能です。配列を使用するときは、配列の宣言時に部屋数(要素数)を指定します。 では、プログラムの実行中に、要素が増加するような場合はどうでしょう。あるいは、プログラムを作成する時点では、いくつの要素を格納するかわからないときは、どうしたらいいでしょう。そんなケースで役立つのが動的配列という使い方です。 動的配列は、宣言時に要素数を指定しません。 Sub Sample33() Dim Member() As String End Sub 一般的な配列では「Member(5)」などと要素数を指定するところを、「Member()」と括弧だけを指定します。これで、変数Memeberは配列として使用できます。ただし、この宣言時点では要素数が確定していませんので、実際には使えません。そこで、プログラムのコード中で要素数を再
VBAにもクラスのコンストラクタとデストラクタがあるらしく、利用方法をまとめた。 コンストラクタ Public Sub Class_Initialize() 'ここに処理を書く End Sub デストラクタ Public Sub Class_Terminate() 'ここに処理を書く End Sub ただし、引数を設定することが出来ず、宣言と同時に初期化を行った場合にはClass_Initializeが走らないという謎の挙動をしてる TestClass Public Sub Class_Initialize() debug.print "コンストラクタが動いたよ!" End Sub Public Sub Class_Terminate() debug.print "デストラクタが動いたよ!" End Sub Test1プロシージャ Public Sub Test1() Dim testA
概要 Microsoft Visual Basic で New 演算子または CreateObject 関数を使用して Microsoft Office アプリケーションのインスタンスを作成すると、次のエラー メッセージが表示されることがあります。 このエラーは、コンポーネント オブジェクト モデル (COM) が要求された Automation オブジェクトを作成できず、Automation オブジェクトが Visual Basic では使用できない場合に発生します。 このエラーは、すべてのコンピューターで発生するわけではありません。 この記事では、このエラーの原因となる可能性がある一般的な問題を診断して解決する方法について説明します。 詳細情報 Visual Basic では、エラー 429 の原因がいくつかあります。 エラーは、次のいずれかの条件に該当する場合に発生します。 アプリケ
Microsoft Office製品(WordやExcelなど)に独自の処理を追加する方法としては、主に下記の3種類がある。 VBA(Visual Basic for Applications)マクロ Office COM(Component Object Model)アドイン Visual Studio Tools for Office(VSTO) このうち、最も手軽に作成できるのが、VBAマクロであるが、このVBAマクロでも、.NET Frameworkで作成した独自のクラスを活用できる。本稿ではその方法を紹介する。 ●VBA向けの.NETライブラリの作成 最初に、VBA向けに.NETのクラス・ライブラリを作成しよう。 管理者としてVisual StudioのIDEを立ち上げ、メニューバーから[ファイル]-[新規作成]-[プロジェクト]を実行すると表示される[新しいプロジェクト]ダイア
サイトをご覧になった方からリクエストをいただきました。「特定のブックを開いているか、どうやってチェックしたらいいですか?」と。また、別の方から「'合計'という名前のシートがあるかどうか調べたい」というメールもちょうだいしました。これらは同じ考え方で実現できますので、一緒に解説しましょう。 ブックが開いているか調べる このテクニックは、実は「ファイルの操作」の「現在開いているブックの一覧を取得する」で解説しています。念のため同じコードを再度ご紹介します。 Sub Sample01() Dim wb As Workbook, flag As Boolean For Each wb In Workbooks If wb.Name = "Book1.xlsx" Then flag = True Next wb If flag = True Then MsgBox "Book1 を開いています。",
複数の条件に一致する数値の合計を求めるExcel関数である、SUMIFS(サム・イフス)関数の使い方を解説します。 対応バージョン:365 2021 2019 2016 2013 2010 SUMIFS関数は、複数の条件に一致するセルを検索し、見つかったセルと同じ行(または列)にある、[合計対象範囲]のセルの数値の合計を求めます。 入力方法と引数 SUMIFS(合計対象範囲, 条件範囲1, 条件1, 条件範囲2, 条件2, ...)
Excel は滅びぬ! Excel の力こそ日本企業の夢だからだ! VBA 実装してて学んだこととかのメモ。 JavaJava してたかはあまり関係ないかも。 エディタの使い方 エディタを表示する Alt + F11 で VB エディタを表示できる。 環境設定 背景色・フォントを調整する デフォルトの白背景とか気が狂うので、暗い色にする。 「ツール」→「オプション」を選択し、「エディターの設定」タブを開く。 「コードの表示色」を選択して、「背景」の色を選択する。 ついでにフォントも見やすいやつに変更する。 これだけで開発効率が5割増しになる。 イミディエイトウィンドウ イミディエイトウィンドウを表示する いわゆるコンソールに当たるのが、イミディエイトウィンドウと呼ばれるウィンドウ。 Ctrl + G で表示される。 イミディエイトウィンドウに出力する ↓イミディエイトウィンドウに実行するプ
クレジットカード現金化の高還元率の優良店を選ぶためには クレジットカード現金化の優良店を選ぶポイントは、換金率やスピードもありますが、そのほかにも見ておきたいポイントもあります。 お金に厳しい人が利用しますので、手数料やキャンペーンの有無、価格交渉ができる業者ということは見ておきたいところです。 それぞれどのような内容なのでしょうか。 手数料が無料であるクレジットカード現金化の業者には、手数料をすべて無料でしてくれるところがあります。 業者によっては、単純に手数料という名目で業者側の利益がとられていたり、振込手数料、事務手数料という名目で少額ながらお金がかかることがあります。 せっかく高い換金率が記載されていても、手数料の分が差し引かれることで、損をしたような気持ちになったり後から気づくこともあります。 これらの手数料は最初から公式ホームページに記載がある場合は了承したうえで申し込みもでき
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く