1
5

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 5 years have passed since last update.

Excelのマクロファイル(あ.xlsm)をアドインファイル(あ.xlam)で保存し、アドイン登録までするマクロ

Posted at

はじめに

 せっかく作ったExcelのマクロファイル(あ***.xlsm***)ですが、必要な作業毎に起動するのがメンドクサイ。
 そこで、①アドインファイル(あ***.xlam***)に保存後、②アドイン登録しています。
 しかし、それすらメンドクサイ。
 そこで、①②を実施するマクロと実行ボタンを作りました。

パソコン環境

  • Windows10 (64ビット)
  • Office365 

実行ボタン(登録ボタン)

image.png

VBA本文

Option Explicit
Sub 特定フォルダにアドインの保存()

    Dim TWMname As String
    TWMname = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 5)
    ActiveWorkbook.SaveAs "C:\Users\" & Environ("UserName") & "\AppData\Roaming\Microsoft\addIns\" & TWMname & ".xlam", FileFormat:=xlOpenXMLAddIn
                          
    ChDir "C:\users\" & Environ("USERNAME") & "\appdata\roaming\microsoft\addins"
    TWMname = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 5)
    
    AddIns.Add Filename:="C:\Users\" & Environ("USERNAME") & "\AppData\Roaming\Microsoft\addIns\" & TWMname & ".xlam"
    
    AddIns(TWMname).Installed = True
    MsgBox (TWMname & ".xlamをアドイン登録しました。")
End Sub
1
5
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
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?