How to get the excel file name / path in VBA

前端 未结 6 1687
粉色の甜心
粉色の甜心 2021-01-07 15:58

Say, I\'m writing a VBA inside my excel file sample.xls. Now I want to get the full path of sample.xls in my VBA. How do I do it?

6条回答
  •  日久生厌
    2021-01-07 16:40

    If you mean VBA, then you can use FullName, for example:

    strFileFullName = ThisWorkbook.FullName
    

    (updated as considered by the comments: the former used ActiveWorkbook.FullName could more likely be wrong, if other office files may be open(ed) and active. But in case you stored the macro in another file, as mentioned by user @user7296559 here, and really want the file name of the macro-using file, ActiveWorkbook could be the correct choice, if it is guaranteed to be active at execution time.)

提交回复
热议问题