How to Create a Macro Button to Save & Close an Excel Workbook #excel #youtube

preview_player
Показать описание
====== PLAYLISTS ======

====== SUMMARY ======
Discover the process of creating a macro button in Excel for saving and closing your workbook efficiently. Learn to enable the Developer tab, insert a form control button, add code, and save the workbook as a macro-enabled document. This tutorial empowers you to streamline tasks in Excel with personalized macro buttons.

======== CODE ======== *Edited
Sub Button1_Click()
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

==== CODE Option 2====
Sub SaveAndClose()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub

==== CODE Option 3====
Sub SaveAndClose()
Dim wb As Workbook
Set wb = ActiveWorkbook
wb.Save
wb.Close
End Sub

====== ARTICLES ======

======= PROFILE =======

======= TAGS =======
#video #viral #trending #viralvideo

My Gear:
Рекомендации по теме
Комментарии
Автор

Here is a different code if you have multiple workbooks open:
Sub SaveAndClose()
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

joscrowd
Автор

Thanks for sharing a very useful code.

roelpanis
Автор

Good tutorial! I have one issue though, if I have other Excel files opened these are also closed when I click the button. How do I solve this?

rico_acheron
Автор

thanks for nice explanation. I have a question pleas : in MS word 2019, if I need to add a command button inside the word FORM or template, THIS TEMPLATE HASE SOME FIELDS TO FILL IN the fields are all in type plain text content controls. I want to write a code for the command button that save the document as the content of “student name” field (plain text content control), and to save it into a specific bath directory, how can I write the code pleas ? can you drop the line code that do this when I click in this command button.? pleas your answer and thank you in advance. (PS I don’t want to print the command button in paper when I print out the document . can I make the command button unprinted?)

m.n.
Автор

For me at least, when I press the button, the macro insists on going through all open workbooks and not just the project file I want to close. To close only the Excel project or file of several you have open, better to customize a block in the "customize ribbon" section of Excel Options, and add "Close" from "All Commands" to it (or click on "X' in the upper right corner of the screen).

dddoda