How to get the excel file name / path in VBA

前端 未结 6 1653
粉色の甜心
粉色の甜心 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 17:02

    ActiveWorkbook.FullName would be better I think, in case you have the VBA Macro stored in another Excel Workbook, but you want to get the details of the Excel you are editing, not where the Macro resides.

    If they reside in the same file, then it does not matter, but if they are in different files, and you want the file where the Data is rather than where the Macro is, then ActiveWorkbook is the one to go for, because it deals with both scenarios.

提交回复
热议问题