Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Window Selection based on name pattern

Hi Group,
I was wondering if there is a way in VBA to make that excel
spreadsheet as active window which has name ending with a fixed
string? For example: if a lot of excel spreadsheets are open at the
same time, all in the same session of course, my code should identify
the spreadsheet whose name is ending with something like
xxxxx_practice.xls and make it as active window.

Many thanks!

Best Regards,
Abhijat
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Window Selection based on name pattern

It might be easier to assign set the sheets to variables then call them by
variable name.

Set ws1 = Workbooks("abc.xls").Sheets("xyz")
Set ws2 = Workbooks("cde.xls").Sheets("mno")

ws2.Activate
ws2.Range("A2").Copy ws2.Range("B5")

You only have to spell out the whole thing once, and use the variable
thereafter.

"Abhijat" wrote:

Hi Group,
I was wondering if there is a way in VBA to make that excel
spreadsheet as active window which has name ending with a fixed
string? For example: if a lot of excel spreadsheets are open at the
same time, all in the same session of course, my code should identify
the spreadsheet whose name is ending with something like
xxxxx_practice.xls and make it as active window.

Many thanks!

Best Regards,
Abhijat

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Window Selection based on name pattern

Give subroutine a try...

Sub ActivateWS(SheetNameEnding As String)
Dim C As Worksheet
For Each C In Worksheets
If C.Name Like "*" & PartialSheetName Then
C.Activate
Exit For
End If
Next
End Sub

And call it from your own code (macro, function, event procedure, etc.) like
this...

ActivateWS "_practice.xls"

--
Rick (MVP - Excel)


"Abhijat" wrote in message
...
Hi Group,
I was wondering if there is a way in VBA to make that excel
spreadsheet as active window which has name ending with a fixed
string? For example: if a lot of excel spreadsheets are open at the
same time, all in the same session of course, my code should identify
the spreadsheet whose name is ending with something like
xxxxx_practice.xls and make it as active window.

Many thanks!

Best Regards,
Abhijat


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Window Selection based on name pattern

Thanks Rick and JLGWhiz. I think Rick has better solution to suit my
requirement. I will definitely give it a try.
For the moment, what I am trying to do is

For i = 1 To 15
ActiveWindow.ActivateNext
If Right(ActiveWorkbook.Name, 18) = "_practice.xls" Then
File_Name = ActiveWorkbook.Name
End If
Next i

The assumptions here are a.) not more than 15 files are open in the
excel session and b.) no file other than the file I desire has a
suffix of "_practice.xls". The latter assumption, I guess, is valid
for Rick's code as well. Still I think his methodolgy and approach is
much more sound than mine.
Thanks a lot!

Best Regards,
Abhijat.
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
attempting to format a color pattern in tab 3, based tab 2 and tab mturboman Excel Discussion (Misc queries) 5 February 24th 10 09:10 AM
How do I Propogate Cell Selection Pattern? archsmooth Excel Worksheet Functions 0 January 9th 08 08:31 PM
Selection Window Mike Excel Discussion (Misc queries) 0 November 14th 07 05:43 PM
AutoFill pattern based on cell locations valoo Excel Discussion (Misc queries) 4 July 28th 06 09:39 PM
How do I change color pattern based upon a formula within a cell? aemuk Excel Worksheet Functions 1 June 16th 06 11:18 PM


All times are GMT +1. The time now is 02:31 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"