- 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.
推薦閱讀
- Instant Testing with CasperJS
- Beginning Java Data Structures and Algorithms
- R語言數據可視化實戰
- 微信公眾平臺開發:從零基礎到ThinkPHP5高性能框架實踐
- Visual Basic程序設計實驗指導(第4版)
- 用Python實現深度學習框架
- 自然語言處理Python進階
- Microsoft Dynamics AX 2012 R3 Financial Management
- 一塊面包板玩轉Arduino編程
- Python圖形化編程(微課版)
- Geospatial Development By Example with Python
- Illustrator CS6設計與應用任務教程
- Learning Python Data Visualization
- Hacking Android
- Java EE 8 and Angular