VBA Get Workbook Path & Location

VBA Get Workbook Path in Excel. We deal with multiple workbooks at a time. We may want to know Workbook path and its location. In the following tutorial we will learn to get Workbook complete Path and location using Path and FullName properties of Workbook.

Syntax to Get complete Path of the Workbook in Excel VBA

Here is the syntax of to Get Path of the Workbook in Excel VBA.

expression.Path

Where expression represents Workbook object.
Path represents a property of Workbook. It returns Workbook complete Workbook path.

Macro to Get Path of the Workbook in Excel VBA

Let us see the following macro to get path of the active Workbook in Excel VBA.

'VBA Get path of the active Workbook in Excel
Sub VBA_Get_ActiveWorkbook_Path()
    
    'Variable declaration
    Dim sWorkbookPath As String
    
    sWorkbookPath = ActiveWorkbook.Path
    
    MsgBox "Active Workbook Path is : " & sWorkbookPath, vbInformation, "VBAF1"

End Sub

Here is the output screenshot of above macro.

Workbook Path

VBA Code to Get Location of the current Workbook in Excel

Here is the following VBA Code to Get Location of the current Workbook in Excel.

'VBA Get Location of the current Workbook in Excel
Sub VBA_Get_CurrentWorkbook_Location()
    
    'Variable declaration
    Dim sWorkbookLocation As String
    
    sWorkbookLocation = ThisWorkbook.FullName
    
    MsgBox "Current Workbook Location is : " & sWorkbookLocation, vbInformation, "VBAF1"

End Sub

Let us see the output screenshot of above VBA code.

Workbook Location

Instructions to use Macro

Here are the instructions to use above macro procedure in Visual basic editor.

  • Save Visual Basic Editor(VBE) by clicking Alt +F11
  • Go to code window by clicking F7
  • Copy above specified macro or procedure
  • Paste above copied code in code window
  • Run macro by clicking F5 or Run command
  • You can see output on the screen
  • Find above output screenshot of the specified procedure.

Related Workbook Object articles

You may also like the related Workbook Object articles.

VBA Workbook Object




Leave a Comment

Your email address will not be published. Required fields are marked *