Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return the File Name 2

Status
Not open for further replies.

randy700

Programmer
Sep 25, 2003
2,384
US
Probably simple but I just cannot find it.

How would I go about returning the name of the excel file from within an excel macro.

Example: Test.xls
Code:
Dim strFileName as String
strFileName = [i][COLOR=red]???[/color][/i]
... where ??? returns "Test" or "Test.xls"


Randy
 
Here is an example to list all the files in a directory; you can make adjustments to meet your needs:

Sub MySub()
Dim MyFile As String

MyFile = Dir("C:\Documents and Settings\me\Desktop\*.*")
MsgBox (MyFile)
Do While MyFile <> ""
'Open MyFile; Apply image; Save as doc; Close file
MyFile = Dir
MsgBox (MyFile)
Loop
End Sub

ps you should direct VBA questions to the VBA forum

sam
 
mintjulep,

Exactly what I needed. Thank you.

Randy
 
Seeing as this is posted in forum68 instead of forum707, I'll just mention that you can return the file name in a cell without VBA by using the CELL function.

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
...and I would further add that if you want to return the name of the workbook that the code is running from, THISWORKBOOK is safer to use than ACTIVEWORKBOOK

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top