Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Activating / Closing workbook using part name and a wild character

Hi,

Is it possible to activate/close an open workbook by a macro by using just
the part name alongwith with a wild character? Like if the workbook name is
"NewBook_6_10" and I want to activate/close it by just using "New*". I
tried using it but I get an error message. Thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Activating / Closing workbook using part name and a wild character

Dim bk as Workbook
for each bk in application.Workbooks
if bk.Name like "New*" then
bk.Activate
exit for
end if
Next

--
Regards,
Tom Ogilvy


"sharman" wrote in message
...
Hi,

Is it possible to activate/close an open workbook by a macro by using

just
the part name alongwith with a wild character? Like if the workbook name

is
"NewBook_6_10" and I want to activate/close it by just using "New*". I
tried using it but I get an error message. Thanks in advance.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Activating / Closing workbook using part name and a wild chara

Hi Tom,

Thanks for the quick response. Using your code, I can activate and close the
workbook using just the part name. Can I also kill it by just using the part
name?

"Tom Ogilvy" wrote:

Dim bk as Workbook
for each bk in application.Workbooks
if bk.Name like "New*" then
bk.Activate
exit for
end if
Next

--
Regards,
Tom Ogilvy


"sharman" wrote in message
...
Hi,

Is it possible to activate/close an open workbook by a macro by using

just
the part name alongwith with a wild character? Like if the workbook name

is
"NewBook_6_10" and I want to activate/close it by just using "New*". I
tried using it but I get an error message. Thanks in advance.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Activating / Closing workbook using part name and a wild chara

No. But once you have identified it you have the whole name.

Dim bk as Workbook
for each bk in application.Workbooks
if bk.Name like "New*" then
bk.Activate
sName = bk.FullName
bk.Close SaveChanges:=False
kill sName
exit for
end if
Next

Using Kill with a wildcard kills everything that matches.

--
Regards,
Tom Ogilvy

"sharman" wrote in message
...
Hi Tom,

Thanks for the quick response. Using your code, I can activate and close

the
workbook using just the part name. Can I also kill it by just using the

part
name?

"Tom Ogilvy" wrote:

Dim bk as Workbook
for each bk in application.Workbooks
if bk.Name like "New*" then
bk.Activate
exit for
end if
Next

--
Regards,
Tom Ogilvy


"sharman" wrote in message
...
Hi,

Is it possible to activate/close an open workbook by a macro by using

just
the part name alongwith with a wild character? Like if the workbook

name
is
"NewBook_6_10" and I want to activate/close it by just using "New*".

I
tried using it but I get an error message. Thanks in advance.







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Activating / Closing workbook using part name and a wild character

Hi Sharman,

Try something like:


Sub TestMe()
Dim WB As Workbook

For Each WB In Application.Workbooks
If LCase(Left(WB.Name, 3)) = "new" Then
WB.Close (False)
End If
Next
End Sub



---
Regards,
Norman



"sharman" wrote in message
...
Hi,

Is it possible to activate/close an open workbook by a macro by using
just
the part name alongwith with a wild character? Like if the workbook name
is
"NewBook_6_10" and I want to activate/close it by just using "New*". I
tried using it but I get an error message. Thanks in advance.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Activating / Closing workbook using part name and a wild chara

Thanks a lot.

"Norman Jones" wrote:

Hi Sharman,

Try something like:


Sub TestMe()
Dim WB As Workbook

For Each WB In Application.Workbooks
If LCase(Left(WB.Name, 3)) = "new" Then
WB.Close (False)
End If
Next
End Sub



---
Regards,
Norman



"sharman" wrote in message
...
Hi,

Is it possible to activate/close an open workbook by a macro by using
just
the part name alongwith with a wild character? Like if the workbook name
is
"NewBook_6_10" and I want to activate/close it by just using "New*". I
tried using it but I get an error message. Thanks in advance.





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
wild character in function? Greg Excel Discussion (Misc queries) 3 July 29th 07 01:38 PM
Working within a workbook without activating it? hyyfte[_11_] Excel Programming 3 June 4th 06 08:00 PM
Working within a workbook without activating it? hyyfte[_9_] Excel Programming 1 September 20th 04 03:34 PM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM
Activating a workbook help bmwmcrider Excel Programming 1 October 21st 03 01:48 PM


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