- VBA Automation for Excel 2019 Cookbook
- Mike Van Niekerk
- 268字
- 2021-06-11 18:16:29
Saving the file with an embedded macro
This recipe will show you how to save a file with an embedded macro. You might think that saving a file cannot be that difficult, and it isn't. The point is a normal Excel file will not allow you to save the macro you've just recorded, at least not with the normal file extension.
Getting ready
With 02_RecordMacro.xlsx still open, close the VBA Editor.
How to do it…
Now, proceed with the following steps:
- In Excel, click on the Save button. The following message box appears:
Figure 1.20 – Message box warning
- Since we want to save the file together with the newly recorded macro, click No.
- Select the folder where you want to save the file in the Save As dialog box.
- At the bottom, below the File name textbox, to the right of the Save as type textbox, click on the arrow. From the list of options, select the second one from the top, Excel Macro-Enabled Workbook (*.xlsm):
Figure 1.21 – Choosing the macro-enabled file option from the Save As dialog box
- Click on Save. In the title bar, the file extension has changed to .xlsm:

Figure 1.22 – Altered file extension visible in the title bar
How it works…
There are a couple of things to notice:
- The standard .xlsx file extension will not allow a macro to be saved with the file.
- Only files with the .xlsm file extension will allow you to save a file with an embedded macro.
There's more…
File extensions allow you to distinguish between files with or without macros.
推薦閱讀
- 解構產品經理:互聯網產品策劃入門寶典
- Python入門很簡單
- 自己動手實現Lua:虛擬機、編譯器和標準庫
- 假如C語言是我發明的:講給孩子聽的大師編程課
- 鋒利的SQL(第2版)
- Full-Stack React Projects
- The Complete Coding Interview Guide in Java
- Mastering openFrameworks:Creative Coding Demystified
- Django 3.0入門與實踐
- QPanda量子計算編程
- Hacking Android
- Getting Started with React VR
- 程序員必會的40種算法
- Java編程指南:語法基礎、面向對象、函數式編程與項目實戰
- MySQL從入門到精通