Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Loop through all open workbooks except Personal.xls

Hello,

I'm really inexperienced in VBA and I need to execute a sub procedure
in all open workbooks except in Personal.xls, but I'm having trouble
coding this.
What am I doing Wrong? Or maybe there's an easier way to do this

Here it is what I have:

Sub nome_cenario()

Dim wkb As Workbook

For Each wkb In Workbooks

If wkb.name = "PERSONAL.xls" Then

Next wkb

Else

Call Myprocedure

Next wkb

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Loop through all open workbooks except Personal.xls

Try...

Sub nome_cenario()
Dim wkb As Workbook
For Each wkb In Application.Workbooks
If Not UCase$(wkb.Name) = "PERSONAL.XLS" Then Call Myproceure
Next 'wkb
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Loop through all open workbooks except Personal.xls

"Costanza" wrote in message
...
Hello,

I'm really inexperienced in VBA and I need to execute a sub procedure
in all open workbooks except in Personal.xls, but I'm having trouble
coding this.



Your idea is pretty similar to how I do that. GS showed you a slightly
different method; his use of the UCASE function is a good way to avoid
potential problems with upper case and lower case variations of the same
name in your IF test.

You were having trouble because 1) you left out the END IF and 2) you
broke the FOR ... NEXT structure the way you had it coded.

Also, I suggest using indentation to improve readability:

Sub nome_cenario()

Dim wkb As Workbook

For Each wkb In Workbooks
If wkb.Name = "PERSONAL.xls" Then
Else
Call Myprocedure
End If
Next wkb

End Sub

I would not normally code an empty IF ... THEN clause like that; though
I have done it on occasion- my reasoning being that the structure helped
the "self documentation" of the code, even though I suspect it hurts
execution efficiency somewhat.

Another way to code this would be:

Sub nome_cenario()

Dim wkb As Workbook

For Each wkb In Workbooks
If NOT wkb.Name = "PERSONAL.xls" Then
Call Myprocedure
End If
Next wkb

End Sub


--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Loop through all open workbooks except Personal.xls

Thanks a lot.

it worked fine




On 5 Maio, 20:18, GS wrote:
Try...

Sub nome_cenario()
* Dim wkb As Workbook
* For Each wkb In Application.Workbooks
* * If Not UCase$(wkb.Name) = "PERSONAL.XLS" Then Call Myproceure
* Next 'wkb
End Sub

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Loop through all open workbooks except Personal.xls

Thanks a lot.

it worked .

Thanks also for taking the time to explain what I was doing wrong.



On 5 Maio, 21:07, "Clif McIrvin" wrote:
"Costanza" wrote in message

...

Hello,


I'm really inexperienced in VBA and I need to execute a sub procedure
in all open workbooks except in Personal.xls, but I'm having trouble
coding this.


Your idea is pretty similar to how I do that. GS showed you a slightly
different method; his use of the UCASE function is a good way to avoid
potential problems with upper case and lower case variations of the same
name in your IF test.

You were having trouble because 1) you left out the END IF and 2) you
broke the FOR ... NEXT structure the way you had it coded.

Also, I suggest using indentation to improve readability:

Sub nome_cenario()

Dim wkb As Workbook

For Each wkb In Workbooks
* * If wkb.Name = "PERSONAL.xls" Then
* * Else
* * * * Call Myprocedure
* * End If
Next wkb

End Sub

I would not normally code an empty IF ... THEN clause like that; though
I have done it on occasion- my reasoning being that the structure helped
the "self documentation" of the code, even though I suspect it hurts
execution efficiency somewhat.

Another way to code this would be:

Sub nome_cenario()

Dim wkb As Workbook

For Each wkb In Workbooks
* * If NOT wkb.Name = "PERSONAL.xls" Then
* * * * Call Myprocedure
* * End If
Next wkb

End Sub

--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Loop through all open workbooks except Personal.xls

"Costanza" wrote in message
...
Thanks a lot.

it worked .

Thanks also for taking the time to explain what I was doing wrong.

-----------


You're welcome. I learned much of what I know about VBA in these
newsgroups ... don't be afraid to ask questions!

--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


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
Personal macros not available when workbooks.open Antonio Excel Programming 1 September 18th 06 01:21 PM
Window_Open in personal.xls run each time I open subsequent workbooks. Nap[_5_] Excel Programming 3 March 23rd 06 09:42 PM
Loop Through All Open Workbooks scott Excel Programming 11 February 1st 05 02:58 AM
Loop through all Open workbooks Stuart[_5_] Excel Programming 3 June 7th 04 08:07 PM
Loop through open workbooks Bob Phillips[_6_] Excel Programming 2 April 28th 04 09:28 AM


All times are GMT +1. The time now is 02:14 PM.

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"