Returning a file name after checking for specific character

W

Wendy

Hi,
I need to return the first set of characters before an underscore in a
filename. slightly disappointed as I can't do this:

FName = Chr$(34) & Left(ActiveWorkbook.Name, Search(Chr$(95),
ActiveWorkbook.Name)) & Chr$(34)

How else can I do it, apart from using another workbook cells to return the
activeworkbookName and then using the len and search function....this is part
of a loop of many workbooks.

Many thanks
Wendy
 
M

Mike H

Weny,

Use the Instr function

FName = Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, "_") - 1)

Mike
 
G

geoff_ness

Try
FName = Left$(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, Chr
$(95)) - 1)

HTH
 
W

Wendy

Thanks Mike, forgot about InStr...
Cheers
Wendy

Mike H said:
Weny,

Use the Instr function

FName = Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, "_") - 1)

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top