[英]What is the difference between Name and FullName in VBA?
In my code I am writing a formula which refers to a workbook I previously defined.在我的代码中,我正在编写一个公式,该公式引用了我之前定义的工作簿。 I was wondering if there is a difference between the Name and FullName property?我想知道 Name 和 FullName 属性之间是否有区别? The Microsoft website doesn't seem to make the distinction between the two clear.微软网站似乎并没有明确区分两者。
Name
will return the name of a file (ex: workbook.xlsx
) Name
将返回文件的名称(例如: workbook.xlsx
)
FullName
will return the path and name of a file (ex: c:\\myDocuments\\workbook.xlsx
) FullName
将返回文件的路径和名称(例如: c:\\myDocuments\\workbook.xlsx
)
Path
will return the path of a file (ex: c:\\myDocuments
) Path
将返回文件的路径(例如: c:\\myDocuments
)
You can quickly check in the Immediate Window (in the VBEditor, press CTRL+G ) and type:您可以快速检入即时窗口(在 VBEditor 中,按CTRL+G )并键入:
?Thisworkbook.Name
2019 Workbook Test.xlsm
?thisworkbook.FullName
K:\Excel Files\Primary Data\2019 Workbook Test.xlsm
全名包括文件路径。
Be aware, if the workbook hasn't yet been saved, both .Name
and .FullName
will only return "Book1"
or similar.请注意,如果工作簿尚未保存,则.Name
和.FullName
都将仅返回"Book1"
或类似内容。 It's not until the workbook's been saved that they'll have complete data, such as "Book1.xlsm"
or "C:\\path...\\Documents\\Book1.xlsm"
.直到工作簿被保存,他们才会拥有完整的数据,例如"Book1.xlsm"
或"C:\\path...\\Documents\\Book1.xlsm"
。
Also, if you use ThisWorkbook.Name
or ThisWorkbook.Fullname
, they'll point to the workbook where your code is.此外,如果您使用ThisWorkbook.Name
或ThisWorkbook.Fullname
,它们将指向您的代码所在的工作簿。 For instance, if the code is in a workbook in your Documents
folder, they'll be as stated above.例如,如果代码位于Documents
文件夹中的工作簿中,它们将如上所述。 But if you're working on code in your Personal Macro Workbook, they'll say Personal.xlsb
and C:\\Users\\[username]\\AppData\\Roaming\\Microsoft\\Excel\\XLStart\\Personal.xlsb
(or similar).但是,如果您正在处理个人宏工作簿中的代码,他们会说Personal.xlsb
和C:\\Users\\[username]\\AppData\\Roaming\\Microsoft\\Excel\\XLStart\\Personal.xlsb
(或类似名称)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.