[英]How do I Run a Workbook_Open code only during the weekdays? (M-F)
[英]How do I run code on Excel startup (not workbook_open)?
我正在寻找一种在打开excel文件时运行代码的方法,而不是从workbook_open方法中运行。
与特定名称“ main_tables.xlsx”一样,并且擅长打开,它们运行的自定义宏不是来自该文件。
有任何想法吗? 谢谢。
您可以使用加载项。
在ThisWorkbook
模块中使用以下代码创建一个加载项:
Private WithEvents app As Application
' This will run when any workbook is opened.
Private Sub app_WorkbookOpen(ByVal Wb As Workbook)
' Check if this add-in is opening versus any other workbook.
If Not Wb Is Me Then
' Another workbook is opening - do something...
MsgBox Wb.Name
End If
End Sub
' This will run when the add-in workbook is opened.
Private Sub Workbook_Open()
' Set the app variable so that we can listen for WorkbookOpen event
Set app = Application
End Sub
通过选择文件->另存为并选择Excel加载项(* .xlam)文件类型,将其另存为加载项文件夹(通常为C:\\ Users \\\\ AppData \\ Roaming \\ Microsoft | AddIns)中的加载项。 。
然后在“文件”->“选项”->“加载项”中选择“管理Excel加载项”,然后按“ Go ....”。这将显示一个加载项列表,以自动启动。 勾选您刚刚创建的加载项。
现在,当您打开任何工作簿时,外接程序代码将运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.