Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Mid function

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Mid function

On Thu, 1 Oct 2009 05:45:54 -0700 (PDT), Ixtreme wrote:

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Mid function

Try

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

--
__________________________________
HTH

Bob

"Ixtreme" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Mid function

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

"Ixtreme" skrev i meddelelsen
...
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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Mid function

try the following:-

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

"Ixtreme" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Function Question: Collect Condition in Dialog Box - But How toInsert into Function Equation? SteveM Excel Programming 1 January 3rd 08 03:45 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Excel - User Defined Function Error: This function takes no argume BruceInCalgary Excel Programming 3 August 23rd 06 08:53 PM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM


All times are GMT +1. The time now is 12:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"