简体   繁体   English

Excel VBA-如何在Excel VBA中引用工作簿内置的文档属性?

[英]Excel vba - How to refer to workbook builtin document properties in excel VBA?

I am building a macro workbook in which ctl+D is deactivated. 我正在构建其中ctl+D被停用的宏工作簿。
Now, the issue is - When another workbook is opened when this macro workbook is still open, ctl+D is getting disabled in the other workbook as well, as this is an application level setting. 现在,问题是 -当该宏工作簿仍处于打开状态时打开另一个工作簿时,另一个工作簿中的ctl+D也将被禁用,因为这是应用程序级别的设置。 I want to restrict disabling ctl+D only in the macro workbook. 我想只在宏工作簿中限制禁用ctl+D

For this, I can add a condition in the code which checks for the workbook name before disabling ctl+D . 为此,我可以在代码中添加一个条件,以在禁用ctl+D之前检查工作簿名称。 But, there is 90% chance that users would change the name of the workbook after saving to their desktop. 但是,用户将其保存到桌面后,有90%的机会更改工作簿的名称。

Is there a way I can use Workbook builtin properties instead of workbook name in code? 有没有一种方法可以使用Workbook内置属性代替代码中的工作簿名称? Please advise. 请指教。

Thank you! 谢谢!

https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.builtindocumentproperties.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.builtindocumentproperties.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

Example (Pseudo code): 示例(伪代码):

if ThisWorkbook.Title = 'TEST' Then
    Application.OnKey "^d", ""
end if

Use workbook events to detect when the workbook is activated or not. 使用工作簿事件来检测何时激活工作簿。

Private Sub Workbook_Activate()
    Application.OnKey "^d", ""
End Sub

Private Sub Workbook_Deactivate()
    Application.OnKey "^d"
End Sub

Put this in the ThisWorkbook module. 将其放在ThisWorkbook模块中。 You might also want to add the Ctrl+d deactivation line to a Workbook_Open event. 您可能还想将Ctrl + d停用行添加到Workbook_Open事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM