4

When I open Microsoft Visual Basic for Applications 7, I see the project window. I.e. file1.xla, file2.xlam, etc. If I have multiple files names file1.xla, how do I know which one I'm looking at? I can't find the path to the file in the IDE.

I have some Excel plugins installed, which might be why some files continuously show up in the list.

Hoppe
  • 6,508
  • 17
  • 60
  • 114
  • 2
    In the Immediate Window, you can type: `?Workbooks("File1.xla").path` for example – Rory May 07 '15 at 12:56
  • Do you want to submit as answer @Rory? It looks like that works – Hoppe May 07 '15 at 13:00
  • That method won't work well if there are multiple files with the same name as you stated in the question. – Mr. Mascaro May 07 '15 at 13:01
  • 1
    I'm new to VBA but I didn't think you can open more than one file with the same name – Hoppe May 07 '15 at 13:03
  • You can if one is an add-in. And if you think it's impossible why did you state it in your question? – Mr. Mascaro May 07 '15 at 13:03
  • AFAIK, you can't have two add-ins with the same file name (including extension) open. – Rory May 07 '15 at 13:23
  • I didn't say that I had multiple files open at the same time @Mr.Mascaro. I have multiple files with the same name on my local file system – Hoppe May 07 '15 at 13:24
  • @Hoppe, OK. Now I understand. You probably want to make that more clear in your question. There are many ways to do what you're asking. – Mr. Mascaro May 07 '15 at 13:35

2 Answers2

5

In the Immediate Window, you can type:

?Workbooks("File1.xla").path

for example.

Rory
  • 32,730
  • 5
  • 32
  • 35
2

You can get the path of the currently active VBProject by using:
Application.VBE.ActiveVBProject.FileName

You can also get all paths by looping through the Application.VBE.VBProjects collection.

Mr. Mascaro
  • 2,693
  • 1
  • 11
  • 18
  • I can use some hand holding as I'm new to VBA... I get "invalid use of property" when I run this from the immediate window – Hoppe May 07 '15 at 13:31
  • Both result in "Application-defined or object defined error". It seems like "Programmatic access to Visual Basic Project is not trusted" when I try ?Application.VBE – Hoppe May 07 '15 at 13:36
  • 2
    Ok. You'll need to go into the Trust Center and select: "Trust access to the VBA project object model." Now that you're a developer this is a very good thing to enable. – Mr. Mascaro May 07 '15 at 13:39