Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Activating an Open Workbook without using the whole filename as a reference


Apologies if this is a really simple question but I haven't been using
VBA for all that long.

I am trying to work out if I can activate an open workbook without
referencing the whole name?

Essentially every month 100 or so files will open automatically, but
each month the name changes slightly as the file name references the
month.
Therefore when I select a file I just want to use the 'constant' terms
in the name to find the file.

I have tried the below, using the * tool but it tells me the subscript
is out of range:

i.e

Application.Workbooks("MLSS*.xls").activate

Is there something fundamental I'm missing?

Thanks for any help

Joe


--
jlejehan
------------------------------------------------------------------------
jlejehan's Profile: http://www.excelforum.com/member.php...o&userid=33950
View this thread: http://www.excelforum.com/showthread...hreadid=537253

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Activating an Open Workbook without using the whole filename as a reference

Try something like

Dim WB As Workbook
For Each WB In Application.Workbooks
If WB.Name Like "MLSS*.xls" Then
WB.Activate
Exit For
End If
Next WB


Only one workbook can be activated at a time.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"jlejehan"
wrote in
message
...

Apologies if this is a really simple question but I haven't
been using
VBA for all that long.

I am trying to work out if I can activate an open workbook
without
referencing the whole name?

Essentially every month 100 or so files will open
automatically, but
each month the name changes slightly as the file name
references the
month.
Therefore when I select a file I just want to use the
'constant' terms
in the name to find the file.

I have tried the below, using the * tool but it tells me the
subscript
is out of range:

i.e

Application.Workbooks("MLSS*.xls").activate

Is there something fundamental I'm missing?

Thanks for any help

Joe


--
jlejehan
------------------------------------------------------------------------
jlejehan's Profile:
http://www.excelforum.com/member.php...o&userid=33950
View this thread:
http://www.excelforum.com/showthread...hreadid=537253



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Activating an Open Workbook without using the whole filename as a

dim bk as workbook
dim bk1 as Workbook
for each bk in application.Workbooks
if bk.name like "MLSS*" then
bk.activate
set bk1 = bk
exit for
end if
Next

' now you can also reference it with bk1
' msgbox bk1.name

--
Regards,
Tom Ogilvy




"jlejehan" wrote:


Apologies if this is a really simple question but I haven't been using
VBA for all that long.

I am trying to work out if I can activate an open workbook without
referencing the whole name?

Essentially every month 100 or so files will open automatically, but
each month the name changes slightly as the file name references the
month.
Therefore when I select a file I just want to use the 'constant' terms
in the name to find the file.

I have tried the below, using the * tool but it tells me the subscript
is out of range:

i.e

Application.Workbooks("MLSS*.xls").activate

Is there something fundamental I'm missing?

Thanks for any help

Joe


--
jlejehan
------------------------------------------------------------------------
jlejehan's Profile: http://www.excelforum.com/member.php...o&userid=33950
View this thread: http://www.excelforum.com/showthread...hreadid=537253


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Activating an Open Workbook without using the whole filename as a reference


Chip, Tom

Many thanks for your replies. Your solutions seem to work perfectly
which has saved me a great deal of time.

Thanks for all your help. Joe.


--
jlejehan
------------------------------------------------------------------------
jlejehan's Profile: http://www.excelforum.com/member.php...o&userid=33950
View this thread: http://www.excelforum.com/showthread...hreadid=537253

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
Open filename using workbook property [email protected] Excel Programming 1 April 25th 06 02:19 AM
Circular reference in an open workbook Joe Cletcher Excel Programming 2 March 3rd 06 12:49 PM
Error on activating a window a open workbook Hari[_3_] Excel Programming 1 June 11th 04 12:58 AM
Workbooks.Open(filename) : Returning err: Object reference not... (in VB.NET) bryan Excel Programming 2 January 20th 04 07:42 PM
Open workbook without activating it Kelley[_2_] Excel Programming 3 October 29th 03 04:49 PM


All times are GMT +1. The time now is 04:53 AM.

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

About Us

"It's about Microsoft Excel"