PDA

View Full Version : Left and Find Function Syntax



YellowLabPro
10-02-2007, 05:09 AM
I want to return the name of the workbook w/out the extension.
The Find function is giving me a Sub ro Function not defined.
How do I need to alter the syntax?

edited: added .Name to ThisWorkbook.Name

emailtitle = Left(ThisWorkbook.Name, Find(".", ThisWorkbook.Name, 1) - 1)


Thanks

mdmackillop
10-02-2007, 05:30 AM
Split is a tidy way to do this, as long as you only have one "." in your file names.

emailtitle = Split(ThisWorkbook.Name, ".")(0)


For your own code, use InStr instead of Find

emailtitle = Left(ThisWorkbook.Name, InStr(1, ThisWorkbook.Name, ".") - 1)

Bob Phillips
10-02-2007, 07:06 AM
I would personally use InStrRev looking for "." rather than Split, precisely for the reason MD mentioned.

YellowLabPro
10-02-2007, 09:09 AM
Thanks Gents,
I will do that.
Thinking about it, Find is a method, not a function. I was misusing it in the code.

Thanks for both ways to handle this...