Finance

Charts

Statistics

Macros

Search

Determine the Name of a Workbook in Excel VBA

The following VBA procedure demonstrates two ways to retrieve the name of a workbook:

Sub GetWorkbookName()
    MsgBox "Name: " & ThisWorkbook.Name
    MsgBox "Name with Path: " & ThisWorkbook.FullName
End Sub

Explanation:

The keyword ThisWorkbook always refers to the workbook in which this code resides, regardless of which workbook is currently active on the screen.

In this procedure:

  • ThisWorkbook.Name retrieves and displays the name of the file only, such as Titanic-Dataset.csv. It does not include the file path.

  • ThisWorkbook.FullName, on the other hand, retrieves and displays the full file path, including the name of the workbook. For example:
    C:\Users\MAC 2015\Desktop\Titanic-Dataset.csv

These properties are useful when you want to display or store workbook information, or when you need to log or reference the file in other operations, such as saving copies or linking to external files.

0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx