Excel工作簿打开时自动运行VBA代码 [英] Automatically Run VBA Code when an Excel Workbook Opens
本文介绍了Excel工作簿打开时自动运行VBA代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打开Excel工作簿时,我要运行VBA代码.
I have VBA code in I would like to run when the Excel workbook is opened.
我尝试在应该在其中运行代码的工作表中创建一个公共过程:
I tried creating a public procedure in the sheet the code is supposed to run in:
Public Sub Workbook_Open
' Some code here
End Sub
在工作簿打开时它不会运行.
It does not run when the workbook opens.
应该在其中一个单元格中创建一个组合框,然后用数据库中的信息填充它.
It is supposed to create a combobox in one of the cells and then fill it with information from the database.
推荐答案
确保代码位于VBA编辑器的 ThisWorkbook
范围内,并且不是或工作表:
Make sure that the code is in the ThisWorkbook
scope of the VBA editor and not in a module or worksheet:
Option Explicit
Private Sub Workbook_Open()
MsgBox "Autorun works!"
'your code here
End Sub
For details also see Microsoft's documentation: Automatically run a macro when opening a workbook.
这篇关于Excel工作簿打开时自动运行VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文