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?
+3
A:
strScriptFullname = WScript.ScriptFullName
strScriptPath = Left(strScriptFullname, InStrRev(strScriptFullname,"\"))
Mitch Wheat
2009-12-13 05:18:46
The op says *inside* sample.xls, which makes me suspicious of VBScript. I suspect VBA.
Remou
2009-12-13 09:53:22
+6
A:
If you mean VBA, then you can use FullName, for example:
strFileFullName = ActiveWorkbook.FullName
Remou
2009-12-13 09:57:49
Oorang's comment is right: 'ThisWorkbook.FullName' would be the correct and safe call. Veera's question states: "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". (Emphasis added.) In this case, using 'ThisWorkbook.FullName' is guaranteed to be correct, while 'ActiveWorkbook.FullName' could give a wildly wrong answer if "sample.xls" is not currently the active workbook.
Mike Rosenblum
2010-01-12 16:30:14