Get Workbook Path in VBA: FullName vs Path

VBA & macros · Updated November 15, 2026

To get a workbook’s folder in VBA, read its Path property; to get the complete location including the file name, read FullName. For example, ThisWorkbook.Path returns the folder containing the workbook that holds the macro, while ThisWorkbook.FullName returns its full path and file name.

What the Workbook Path Properties Return

Excel’s Workbook object exposes several related properties, and choosing the right one depends on what your code needs to do. The folder path is useful when a macro must save an output file beside the workbook or find a neighboring file. The full name is useful for displaying or recording the workbook’s complete location.

  • Path returns the location of the folder, without the workbook’s file name.
  • FullName returns the workbook’s location together with its file name and extension.
  • Name returns only the workbook’s file name, such as Budget.xlsx.

For a saved Windows workbook, a folder might look like C:\Reports\Quarterly, while the full name might look like C:\Reports\Quarterly\Sales.xlsx. The returned text depends on where and how the workbook is stored. Do not assume the path is the same on every user’s computer: a workbook saved under one person’s Documents folder may be under a different folder for a colleague.

These properties describe a workbook currently open in Excel. They do not search the computer for a file, and they do not automatically identify a related workbook. Your code must first refer to the particular workbook object whose location you want.

Choose ThisWorkbook or ActiveWorkbook

The most important choice is which workbook object to ask. ThisWorkbook means the workbook containing the VBA code currently running. ActiveWorkbook means the workbook that is active in the Excel window. They can be the same, but they are not always.

If a macro is stored in the workbook it is meant to process, ThisWorkbook is usually the dependable choice. If the macro is stored in the Personal Macro Workbook, an add-in, or another controller file, ThisWorkbook refers to that file—not necessarily the workbook the user is working on. In that situation, the active workbook may be the intended target, but code should make that choice explicit.

For example, a macro in PERSONAL.XLSB that uses ThisWorkbook.Path will ask for the Personal Macro Workbook’s location. It will not return the path of the sales file currently visible. Conversely, relying on ActiveWorkbook can be risky if a macro activates another workbook or opens a new one before reading the property. Store the intended workbook in a variable before doing other work.

When code opens or creates workbooks, keep a reference to the relevant object and use that reference consistently. This helps prevent a later window change from making the macro read a different workbook’s path by mistake.

Get the Path with a VBA Macro

This macro reports the folder and full file name of the workbook that contains the code. It also checks for an unsaved workbook, whose folder path is empty.

Sub ShowThisWorkbookLocation()
    Dim wb As Workbook

    ' The workbook containing this macro is the target.
    Set wb = ThisWorkbook

    If Len(wb.Path) = 0 Then
        MsgBox "Save the workbook before checking its path."
    Else
        MsgBox "Folder: " & wb.Path & vbCrLf & _
               "Full name: " & wb.FullName
    End If
End Sub

In the Visual Basic Editor, put the code in a standard module or in an appropriate workbook module, then run the procedure. In Excel for Microsoft 365 on Windows, press Alt+F11 to open the editor. On a Mac, the Visual Basic Editor is available through the Developer tab or Excel’s Tools menu, depending on the interface; the Windows Alt+F11 shortcut is not the Mac shortcut. Excel for the web does not run VBA macros, so open the file in the desktop application to use this code.

Save a copy of the workbook before running a macro that changes files or workbook contents. VBA actions generally cannot be reversed with Ctrl+Z. This example only displays information, but that safeguard matters when adapting it to save, rename, or delete files.

Why an Unsaved Workbook Has No Folder Path

A new workbook that has not been saved has no permanent location on disk. In that state, its Path property is an empty string, so code that joins the path to a folder name may produce an invalid location. Its FullName is not a reliable substitute for a saved file location either: the workbook has not yet been assigned a final file name and folder.

Check the path before using it, as in the macro above. If the workbook must be saved first, the user can use File > Save As and choose a location. A macro can also use Excel’s save dialog, but that changes the workflow and may require handling cancellation. Do not assume that opening a Save As dialog means the workbook was saved; the user may close the dialog without choosing a destination.

This distinction is especially useful when a macro creates an output file next to the source workbook. First confirm that the source has a nonempty path. Then build the destination from the saved folder and a chosen file name. If the source is unsaved, ask the user to save it or ask for a separate output folder instead of silently guessing.

Build File Locations Without Hard-Coding Separators

A common next step is combining a folder path with another file name. Avoid assuming that every operating system uses the same path separator. Excel exposes the separator through Application.PathSeparator, which lets VBA construct the location using the separator appropriate to the running Excel environment.

For instance, the general pattern is the folder path, followed by the application’s separator, followed by a file name. Before joining them, check that the folder path is not empty. Also avoid adding a second separator if the path already ends with one. In most ordinary local paths returned by Excel, the folder path does not include a trailing separator, but robust code should not depend on informal assumptions when it can check.

Another option is to use a file dialog when the user should choose a destination rather than saving automatically beside the workbook. That is often preferable for shared tools: a hard-coded folder may exist on the author’s computer but not on someone else’s. If you do construct a path, validate that the folder exists and handle errors if the destination is unavailable or access is denied.

Relative paths can also help make a project portable. A relative reference describes a location in relation to a known folder, rather than naming a specific drive such as C:. VBA does not make every file operation automatically relative to the workbook, however; code must deliberately combine the workbook folder with the intended subfolder or file name.

Local, Network, OneDrive, and SharePoint Locations

For a workbook saved on a local drive or a mapped network drive, the path is commonly a conventional file-system location. Network locations may appear with a mapped drive letter or as a UNC path beginning with two backslashes. Which form appears can depend on how the drive was connected and how the file was opened.

Cloud storage needs more care. A OneDrive or SharePoint workbook opened in desktop Excel may be associated with a synchronized local folder, an online address, or a location whose behavior differs according to the account, sync setup, and opening method. Do not assume that every cloud-backed workbook returns a simple local folder that another user can access. A URL or a path tied to one user’s synced folder may not work as a file-system location on another computer.

If a process must work across users or devices, decide what kind of location it needs: a local folder for file operations, a shared network location, or a cloud URL for an online workflow. Test the intended workflow with the actual storage arrangement. A workbook path is a location string, not proof that the current user has permission to read or write there.

Common Errors and How to Avoid Them

  • Using the wrong workbook reference: Check whether the macro is in the file being processed. Use a saved workbook variable when the target is not the macro-containing file.
  • Ignoring an empty path: An unsaved workbook has no folder location. Check for an empty string before creating a destination path.
  • Appending the file name twice: FullName already includes the file name. Add another name only when starting from the folder returned by Path.
  • Assuming a path is writable: A valid-looking location can still be read-only, unavailable, or restricted by permissions. Handle file-operation errors and confirm the user has access.
  • Hard-coding a personal folder: A path such as a particular user’s Desktop folder will not necessarily exist for coworkers. Prefer a user-selected destination or a path derived from a shared, known location.

When troubleshooting, inspect the exact property value in the Visual Basic Editor’s Immediate window or display it in a message box. This reveals whether the code is reading the expected workbook and whether the result is local, network-based, or otherwise different from what the macro expects. Check the workbook reference before changing the string: many apparent path problems are actually reference problems.

Platform and Macro-Safety Notes

The workbook properties discussed here are part of Excel VBA, but VBA runs in the desktop versions of Excel rather than in Excel for the web. A workbook can be stored online and opened in a browser, but browser editing does not execute its VBA macros. To run a macro, open the file in desktop Excel and ensure the workbook is saved in a macro-enabled format, such as .xlsm, when it contains VBA that must be retained.

On Windows, Alt+F11 opens the Visual Basic Editor in many Excel configurations. On Mac, use the Developer tab or the Excel menu options for Visual Basic; keyboard shortcuts can differ by keyboard and Excel version. The path separator also differs between platforms, which is why using Application.PathSeparator is safer than writing a slash or backslash into reusable code.

Only enable macros in files you trust. A macro that reads a path is not inherently dangerous, but VBA can perform actions beyond displaying a location. Review code before running it, and keep a backup before testing modifications or file operations.

Frequently Asked Questions

How do I get the full file path of the current workbook in VBA?
Use the FullName property on the correct workbook object. For the workbook containing the macro, that is ThisWorkbook.FullName. For the active workbook, use its workbook object’s FullName property.

What is the difference between Path and FullName in VBA?
Path returns the folder location without the workbook’s file name. FullName returns the location and file name together. Use Name when you need only the file name.

Why is ThisWorkbook.Path blank?
The workbook containing the VBA code may not have been saved yet. Save it to a folder, then read the property again. Also confirm that ThisWorkbook is the workbook you intended to inspect.

How do I get the active workbook’s path instead?
Use the active workbook object and read its Path property. This differs from ThisWorkbook when the code is stored in another workbook, such as an add-in or the Personal Macro Workbook. Make sure the active workbook is the intended target before relying on it.

Can VBA get a workbook path in Excel for the web?
No. Excel for the web does not execute VBA macros. Open the workbook in desktop Excel to run VBA, or use a web-based automation option such as Office Scripts where its capabilities fit the task.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.