Excelのアドイン機能を活用することで、普段よく行う操作をワンクリックでできるようになります。
今日は、テーブルの自動作成アドインを作っていきたいと思います。
このエクセルファイルの作り方
①マクロを使えるようにする(既に設定済の方は②に進んでください)
「マクロを使えるようにする」を参照
②「マクロの記録」ボタンを押します。(マクロ名は何でもいいですが、今回は「Table」とします)
![](https://exceldemon.net/wp-content/uploads/2020/07/image-1024x636.png)
③テーブルを作成します
![](https://exceldemon.net/wp-content/uploads/2020/07/image-3.png)
④「記録終了」を押します。
![](https://exceldemon.net/wp-content/uploads/2020/07/image-5-1024x454.png)
⑤「Alt + F8」を押して、「編集」を押します。(ソースコードが表示されます)
![](https://exceldemon.net/wp-content/uploads/2020/07/image-6.png)
⑥ソースコードを微調整していきます。以下のソースをペーストします。
Sub Table() '特定のCellではなく選択範囲に罫線を描画する(Selectionというのが選択範囲) Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With 'タイトルを塗りつぶし(選択範囲の先頭行のみ) Range(Selection(1), Selection(1).Offset(0, Selection.Columns.Count - 1)).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent1 .TintAndShade = -0.249977111117893 .PatternTintAndShade = 0 End With With Selection.Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With 'タイトルを描画(選択範囲の先頭行のみ)※これはなくてもいいです For col = Selection(1).Column To Selection(1).Offset(0, Selection.Columns.Count - 1).Column Cells(Selection(1).Row, col) = "Col" & col - Selection(1).Column + 1 Next col End Sub
⑦ファイルの種類で「Excelアドイン(*.xlam)」を選択して保存します。
![](https://exceldemon.net/wp-content/uploads/2020/07/image-7-1024x705.png)
⑧「Excelアドイン」ボタンから、作成したアドイン(Table)を有効にします。
![](https://exceldemon.net/wp-content/uploads/2020/07/image-8-1024x504.png)
⑨「ファイル」を押します。
![](https://exceldemon.net/wp-content/uploads/2020/07/image-9.png)
⑩「オプション」を押します。
![](https://exceldemon.net/wp-content/uploads/2020/07/image-10.png)
⑪「クイックアクセスツールバー」に今回作成した「Table」を追加します。
![](https://exceldemon.net/wp-content/uploads/2020/07/image-11-1024x565.png)
⑫「クイックアクセスツールバー」のボタンから、テーブルを自動作成できるようになります。
![](https://exceldemon.net/wp-content/uploads/2020/07/image-12.png)
![Icon](https://exceldemon.net/wp-content/plugins/download-manager/assets/file-type-icons/box_download.png)
TABLE(AddIn)
1 file(s) 17.12 KB