简体   繁体   中英

Get the name of workbook that hosts the currently running VBA code?

I'll also note, that the Application.Run("<workbook name>!<public VBA function name>") allows jumps of the execution to other workbooks without changing the ActiveWorkbook property.

I want to know the name of the workbook which hosts the currently executing VBA code.

In case if someone did understand me wrong:

  • The trivial ActiveWorkbook wouldn't do, because the active workbook might be completely different then the one, where the running VBA macro is located.
  • The Me object isn't the ticket either. It contains the reference to the class which method is currently executing, regardless of the hosting object (it would work only if my VBA code is in a method of the Worksheet or Workbook class).

我想知道承载当前正在执行的VBA代码的工作簿的名称。

Debug.Print ThisWorkbook.Name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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