Tags

Path and Fullname property in excel VBA returns the saved path of the workbook.

 

Path property returns the path of the workbook without the workbook name where in Fullname property returns the path name including the workbook name in it.

 

See below how it works.

 

For this purpose I have created a folder named “test” in my D:\ drive, where I have created two macro enabled excel files named “macro practice.xlsm” and  “my workbook.xlsm”.

 

Now, I have opened the worksheet “macro practice.xlsm” and opened VBA editor by pressing Alt+F11 key (use can also right click on the sheet name and then view code option).

 

Code part:

 

Sub path()

‘declare variables to store the path name

Dim wbpath As String

Dim wbfullname As String

Dim wbfullname1 As String

Dim wbfullname2 As String

 

‘working with already open workbook ie;macro practice.xlsm

 

wbpath = Workbooks(“macro practice.xlsm”).path

MsgBox “you are now working with ” & wbpath

 

wbfullname = Workbooks(“macro practice.xlsm”).FullName

MsgBox “you are now working with fullname” & wbfullname

‘working with active workbook

‘I will now open my second workbook named “my workbook.xlsm” and activate both the already open workbooks_

‘one at a time and then try getting their fullname property

 

Workbooks.Open (“D:\test\my workbook.xlsm”)

Workbooks(“my workbook.xlsm”).Activate

 

wbfullname1 = ActiveWorkbook.FullName

MsgBox “your new opened wb name is ” & wbfullname1

 

‘swap the already open workbook (switch to macro practice.xlsm)

Workbooks(“macro practice.xlsm”).Activate

wbfullname2 = ActiveWorkbook.FullName

MsgBox “wb has been swapped and is ” & wbfullname2

 

Workbooks(“my workbook.xlsm”).Close

 

End Sub