View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
SteveDB1 SteveDB1 is offline
external usenet poster
 
Posts: 414
Default string extraction not working.

Hi all.
I'm attempting to create a worksheet name extraction tool and have obtained
the following.
Code-------------------------------------------------------------------------------

Function stGetFileName() As Variant
Dim nwShtNm As Worksheet
Dim nwShtNm1 As String

stGetFileName() = ThisWorkbook.Name

'need code to ensure that a worksheet gets named correctly.
'what I have here is not it.
nwShtNm1 = stGetFileName()

If Worksheet.Name = "Sum" Or "SUM" Then
nwShtNm.Name = "Sum-" & nwShtNm1

ElseIf Worksheet.Name = "Summary" Then
nwShtNm = "Sum-" & nwShtNm1

ElseIf Worksheet.Name = "APN" Then
nwShtNm = "APN-" & nwShtNm1

End If
End Function

----------------------------------------------------------------------------------------------

This is not working as hoped.
I'm activating a workbook, looking for two worksheets-- Sum, or Summary, or
SUM, and APN.
I then want to rename those two worksheets from the book's name-- generally
a 7 character string starting with "DTR-XXX" as shown above.
I'm wanting to extract the last 3 digits- xxx.
I've tried variations of the above, and this is as close as I've gotten thus
far.
the function just bounces back and forth between the function's name, and the
stGetFileName() = ThisWorkbook.Name line.