Get File Name with Excel VBA

Sometimes it is useful to get the file name using Excel VBA. Two methods will either give the file name, or the full file path and file name.  When I use either of these methods I tend to assign them to a variable as a string.

Get File Name using VBA

Using VBA I would assign the file name to the variable thus so. Assuming you want to capture the filename of the workbook currently open I would add two lines of code.  One to declare the variable, and one to assign the file name to the variable.

Dim FileName as String

FileName = ThisWorkbook.Name

Get File Path & File Name using VBA
To get the file path and file name of the active workbook I would use the same method as above, but change the second line ever so slightly.

Dim FullFileName as String

FullFileName = ThisWorkbook.FullName

So using the examples above will generate the following variables.  These are examples only, and file paths will differ:

FileName: Workbook.xls

FullName: C:\ExcelGeek\VBA\Learning\Workbook.xls

634 thoughts on “Get File Name with Excel VBA

  1. best vacation insurance

    Hi there are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and create my own. Do you require any coding knowledge to make your own blog? Any help would be really appreciated!

  2. travel blog sites

    Hello I am so delighted I found your weblog, I really found you by mistake, while I was researching on Digg for something else, Anyways I am here now and would just like to say thank you for a incredible post and a all round interesting blog (I also love the theme/design), I don’t have time to read through it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the superb work.

  3. travel insurance for asthma sufferers

    I don’t know whether it’s just me or if everyone else experiencing issues with your site. It appears as if some of the written text in your posts are running off the screen. Can someone else please comment and let me know if this is happening to them as well? This may be a problem with my web browser because I’ve had this happen previously. Many thanks

  4. cruise holiday insurance

    Please let me know if you’re looking for a author for your weblog. You have some really good articles and I believe I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some content for your blog in exchange for a link back to mine. Please send me an e-mail if interested. Cheers!

  5. tattoo studio

    It as not that I want to replicate your web site, but I really like the style and design. Could you let me know which design are you using? Or was it tailor made?

  6. John Deere Technical Manuals

    Have you ever thought about publishing an e-book or guest authoring on other websites? I have a blog based upon on the same topics you discuss and would really like to have you share some stories/information. I know my readers would appreciate your work. If you’re even remotely interested, feel free to shoot me an e-mail.

Leave a Reply

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