views:

823

answers:

2

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
The op says *inside* sample.xls, which makes me suspicious of VBScript. I suspect VBA.
Remou
+6  A: 

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

strFileFullName = ActiveWorkbook.FullName
Remou
Surely you mean ThisWorkbook.FullName? ;)
Oorang
Not necessarily.
Remou
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