Excel Filename prgramatically

M

Mike D

I have a line of code:

strThisFileName = "MY Excel FileName.xls"

How do I set my variable to the current excel filename?

strThisFileName = Workbooks.??

Thanks
Mike
 
T

Toby Erkson

Use ThisWorkbook.Name

To get the path:
ThisWorkbook.Path

So your code would be:
strThisFileName = Thisworkbook.Name

Toby Erkson
Oregon, USA
 
M

Matthew =}

Hey, Mike.

Your Workbooks.??? method will DO something to the
workbook. You want to ask it something, I think.

strThisFileName = ActiveWorkbook.Name
strThisSheetName = ActiveSheet.Name

....assuming the reference is to an open workbook with an
active sheet. Before I run these lines, I reassure
myself with something like:

Range("C3").Select
Range("C3").Activate

Then the cell (or range) you have activated will also
activate that sheet and the book that contains it.

You may also have interest in:

ActiveWorkbook.SaveAs (strThisNewFileName)
ActiveWorkbook.Close

Anyway, I hope that's what you were looking for.

Good luck, it sounds like fun.

Matthew

=}
 
Top