Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the name of the currently open Excel document using VBA?

Tags:

excel

vba

I'm using VBA in Excel to read a spreadsheet and modify its contents. I need to save the results with a name that is similar to the original file, but with some alterations.

How can I programmatically find the name of the currently open file using vba?

like image 441
Jacob Winn Avatar asked Dec 09 '22 13:12

Jacob Winn


2 Answers

ThisWorkbook.Name will return the file name. ThisWorkbook.FullName will return the directory structure and the file name.

like image 173
Michael Avatar answered Jan 19 '23 00:01

Michael


It depends, here are two possibilities:

Debug.Print ActiveWorkbook.Name

For Each wk In Workbooks
    Debug.Print wk.Name
Next
like image 41
Fionnuala Avatar answered Jan 19 '23 00:01

Fionnuala