Mid function

  • Thread starter Thread starter Ixtreme
  • Start date Start date
I

Ixtreme

Hi,

In vba I want to get a part of the workbooks' name in a string.

Each workbook has a name like this

test_XX_YYY.xls
or only test_XX.xls

I want everything before .xls and after the first underscore sign. For
the above filenames I would like to have:

XX_YYY
and
XX
 
Hi,

In vba I want to get a part of the workbooks' name in a string.

Each workbook has a name like this

test_XX_YYY.xls
or only test_XX.xls

I want everything before .xls and after the first underscore sign. For
the above filenames I would like to have:

XX_YYY
and
XX


In VBA:

Mid(ThisWorkbook.Name, InStr(ThisWorkbook.Name, "_") + 1)


--ron
 
Try

newVar = Mid$(var, InStr(var, "_") + 1, InStrRev(var, ".") - InStr(var,
"_") - 1)
 
Hi

Look at this example:

Sub aaa()
MyString = "test_XX_YYY.xls"
MyString = Right(MyString, Len(MyString) - 5)
LastChar = WorksheetFunction.Find(".", MyString) - 1
Result = Left(MyString, LastChar)
Debug.Print Result
End Sub

Regards,
Per
 
try the following:-

strWkBKName = ThisWorkbook.Name
strResult = Mid(strWkBKName, InStr(1, strWkBKName, "_") + 1,
Len(strWkBKName) - 4 - InStr(1, strWkBKName, "_"))
 
Back
Top