简体   繁体   中英

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? 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 )

FullName will return the path and name of a file (ex: c:\\myDocuments\\workbook.xlsx )

Path will return the path of a file (ex: c:\\myDocuments )

You can quickly check in the Immediate Window (in the VBEditor, press CTRL+G ) and type:

?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. 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" .

Also, if you use ThisWorkbook.Name or ThisWorkbook.Fullname , they'll point to the workbook where your code is. For instance, if the code is in a workbook in your Documents folder, they'll be as stated above. 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).

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