ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   sheet reference (https://www.excelbanter.com/excel-programming/308428-sheet-reference.html)

Srikanth[_6_]

sheet reference
 
I want to do the following:

(say) I have an excel file by name XYZ.xls and this file has many
worksheets in it. But I am interested in a specific sheet with name
"XYZ all". How to reference the sheet when the filename XYZ could be
different every time I run the macro ? Please help. Thanks

Srikanth

Tom Ogilvy

sheet reference
 
Dim bk as Workbook, bk1 as Workbook
Dim sh as Worksheet
set bk1 = Nothing
for each bk in Application.Workbooks
set sh = Nothing
On error resume next
set sh = bk.worksheets("XYX all")
On Error goto 0
if not sh is nothing then
set bk1 = bk
exit for
End if
Next

if not bk1 is nothing then
msgbox "XYX all found in " & bk1.name
End if

--
Regards,
Tom Ogilvy

"Srikanth" wrote in message
m...
I want to do the following:

(say) I have an excel file by name XYZ.xls and this file has many
worksheets in it. But I am interested in a specific sheet with name
"XYZ all". How to reference the sheet when the filename XYZ could be
different every time I run the macro ? Please help. Thanks

Srikanth




Otto Moehrbach[_6_]

sheet reference
 
I read your question that you want to reference a sheet name that consists
of the following:
The file name without the ".xls" followed by:
A space, followed by:
"all"

Is that what you want?
If so, then something like this might help.
Dim ShtName As String
ShtName=Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name)-4)
ShtName = ShtName & " all"

Or maybe I didn't read your question right.
HTH Otto

"Srikanth" wrote in message
m...
I want to do the following:

(say) I have an excel file by name XYZ.xls and this file has many
worksheets in it. But I am interested in a specific sheet with name
"XYZ all". How to reference the sheet when the filename XYZ could be
different every time I run the macro ? Please help. Thanks

Srikanth





All times are GMT +1. The time now is 10:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com