1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

EXCEL VBA が好き!

Last updated at Posted at 2025-03-20

概要

私は EXCEL VBA が大好きです。

詳細

画面を作成できる

画面が容易に生成できる。

Qiita 画面 転送 VBA.jpg

変数名や関数名に日本語が使用できる

プログラムの内容を思い出し易いので保守が楽。日本語のコメントが少なくて済む。
Qiitaのシンタックスチェックでは日本語がエラーになりますね(笑)

Private m_fso As New Scripting.FileSystemObject
Private m_tsoファイル一覧 As Scripting.TextStream

Private Sub 作成ファイル一覧()
    Dim strフォルダ As String
    Dim fdo As Scripting.Folder

    Set m_tsoファイル一覧 = m_fso.CreateTextFile("D:\ファイル一覧.txt")
    strフォルダ = "D:\MyDocuments"
    Set fdo = m_fso.GetFolder(strフォルダ)
    探索 fdo
    m_tsoファイル一覧.Close
End Sub

Private Sub 探索(fdo As Scripting.Folder)
    Dim fdoSub As Scripting.Folder
    Dim flo As Scripting.File
    
    For Each fdoSub In fdo.SubFolders
        探索 fdoSub
    Next
    For Each flo In fdo.Files
        m_tsoファイル一覧.WriteLine flo.Name
    Next
End Sub

With が便利

文が短くなるので書き易くて読み易い。処理の区分がわかり易い。

    Dim intRowIndex As Integer
    With WorkSheets(1)
        intRowIndex = 2
        Do Until .Cells(intRowIndex, 1) = ""
            .Cells(intRowIndex, 3) = .Cells(intRowIndex, 1) + .Cells(intRowIndex, 2)
            intRowIndex = intRowIndex + 1
        Loop
    End With

清書してくれる

入力: a=A+1
清書: A = A + 1

実行中にソースを修正できる

中断点で実行を止めて変数の内容を確認し、ソースを修正して実行を継続することができる。
したがってプログラムを短時間で完成させることができる。

命令、変数名、関数名に大文字小文字の区別がない

英字の大文字と小文字を区別しなくてもよいので、それによるプログラムの間違いが発生しない。

EXCELのワークシートに情報を保持できる。

プログラムと情報を1つのブックに纏めることができるので資材の管理がしやすい。
操作方法や保守ドキュメントも纏めることができる。

日付が扱い易い

DateAdd, DateDiff, DateValue, Year, Month, Day, Weekday, Format など日付を扱う関数が充実している。

まとめ

EXCEL VBAは個人や少人数のチームで使うツールとしては最高だと思います。
メインの仕事を持っていてツールとして使うにはとても良いと思います。まさにツールと呼べるものです。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?