0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

案件に入るたびに自分のExcelに設定するマクロ

Posted at

1.はじめに

Windowsを使う案件に参加するとほぼほぼExcelにお世話になることが多いだけでなく、大体同じような設定しかしないので備忘目的で記載。
※Macを使用する案件ではExcelでマクロがうまく動かないことが多いので今回は対象外。

2.個人用マクロで設定するもの

「個人用マクロ」とはざっくりいうと、Excelが起動するたびに起動するマクロ。
ここには汎用的に使えるマクロを置いておくと便利。
作成方法はこちら参照

2-1赤文字マクロ

選択したセルの文字の色を赤文字にするマクロ。
既に赤文字だった場合も黒文字に戻す。
Excelで太字を使う感覚で使用できる。

Sub setRed()
    If Selection.Font.Color = RGB(255, 0, 0) Then
        Selection.Font.Color = RGB(0, 0, 0)
    Else
        Selection.Font.Color = RGB(255, 0, 0)
    End If
End Sub

2-2四角

現在選択中のセルにExcelのオブジェクトの四角を選択したセルに表示させるだけのマクロ
Excelでキャプチャ貼ったりする際に分かりやすくするのに使用。

Sub setSquare()
    Dim iRow As Integer
    Dim iColumn As Integer
    
    ActiveSheet.Shapes.AddShape(msoShapeRectangle, ActiveCell.Left, ActiveCell.Top, 310, 109).Select 
    '↑の引数は、四角、セルの右方向の位置、下方向の位置、横幅、高さの順番
    Selection.ShapeRange.Fill.Visible = msoFalse
    With Selection.ShapeRange.Line
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 0, 0)'線の色、このままだと赤になる
        .Transparency = 0
        .Visible = msoTrue
        .Weight = 3
    End With
End Sub

上を実行するとこんな感じで長方形が出力される。
image.png

2-3吹き出し

現在選択中のセルにExcelのオブジェクトの四角を選択したセルに表示させるだけのマクロ
Excelでキャプチャ貼ったりする際、コメントを横に添えたりするのに使用。

Sub setBalloon()
    ActiveSheet.Shapes.AddShape(msoShapeRectangularCallout, ActiveCell.Left, ActiveCell.Top, 300, 80). _
    '↑の引数は、吹き出し、セルの右方向の位置、下方向の位置、横幅、高さの順番
        Select
    With Selection.ShapeRange.TextFrame.Characters
        .Text = "" '吹き出しの中に入れるテキスト、設定はお好みで。
        .Font.Size = 12
        .Font.Color = RGB(0, 0, 0)'吹き出しの中に入れるテキストの色、
    End With
    
    Selection.ShapeRange.Adjustments.Item(1) = -0.68323
    Selection.ShapeRange.Adjustments.Item(2) = 0.32813
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 255, 255) '吹き出しの中の背景
        .Transparency = 0
        .Solid
    End With
    With Selection.ShapeRange.Line
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 0, 0)'吹き出しの線の色
        .Transparency = 0
        .Weight = 3
    End With
End Sub

上を実行するとこんな感じで長方形が出力される。
選択した状態でスペースキーを押すと、そのまま入力することもできる。
image.png

3.ショートカットの設定

この手のマクロはショートカットを設定して初めて機能することが多いので、独自にショートカットを作成する。
「開発->マクロ->オプション」で設定できるので独自で設定する。
image.png

4.おわりに

以上が案件に入るたびに設定しているマクロでした。
常にどのExcel開いても使えるとなると、凝ったものというより小回りが利くようなものしか置けないと思う。
他にも効率的なマクロはあるとは思うので、何かあれば随時更新予定。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?