Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
MDW MDW is offline
external usenet poster
 
Posts: 117
Default Programming With Multiple Excel Workbook Objects

Hey all.

This may be an issue of semantics more than anything, I'm not sure.

Say I'm using the FileSystemObject to loop through a folder full of Excel
files using "For Each ... Next". On every iteration, I'm setting a Workbook
object using the code "Set objWB = objXL.Workbooks.Open(strFolderPath &
objFile.Name)".

Is it better for me to close each wokbook within the loop (there could be
upwards of 500 workbooks), or close the workbook once, after the loop? In
either case, I will set the variable to nothing after the loop.

In other words, which is better (or is there a difference) -

OPTION A:

For Each objFile In objFolder.Files
Set objWB = objXL.Workbooks.Open(strFolderPath & objFile.Name)
' Do stuff
objWB.Saved = True
objWB.Close
Next
Set objWB = Nohing

OPTION B:

For Each objFile In objFolder.Files
Set objWB = objXL.Workbooks.Open(strFolderPath & objFile.Name)
' Do stuff
Next
objWB.Saved = True
objWB.Close
Set objWB = Nohing

--
Hmm...they have the Internet on COMPUTERS now!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Programming With Multiple Excel Workbook Objects

I think you may be mixing things up a wee bit in your terminology.

Option 2 only saves closes the last opened workbook, the other 499 are still
open.

Go for option 1, close each down when done with. The Set ... = Nothing is
just releasing the workbook variable from memory, it has nothing to do with
closing.



--

HTH

RP
(remove nothere from the email address if mailing direct)


"MDW" wrote in message
...
Hey all.

This may be an issue of semantics more than anything, I'm not sure.

Say I'm using the FileSystemObject to loop through a folder full of Excel
files using "For Each ... Next". On every iteration, I'm setting a

Workbook
object using the code "Set objWB = objXL.Workbooks.Open(strFolderPath &
objFile.Name)".

Is it better for me to close each wokbook within the loop (there could be
upwards of 500 workbooks), or close the workbook once, after the loop? In
either case, I will set the variable to nothing after the loop.

In other words, which is better (or is there a difference) -

OPTION A:

For Each objFile In objFolder.Files
Set objWB = objXL.Workbooks.Open(strFolderPath & objFile.Name)
' Do stuff
objWB.Saved = True
objWB.Close
Next
Set objWB = Nohing

OPTION B:

For Each objFile In objFolder.Files
Set objWB = objXL.Workbooks.Open(strFolderPath & objFile.Name)
' Do stuff
Next
objWB.Saved = True
objWB.Close
Set objWB = Nohing

--
Hmm...they have the Internet on COMPUTERS now!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Programming With Multiple Excel Workbook Objects

In option B, you would only close one workbook.

--
Regards,
Tom Ogilvy

"MDW" wrote in message
...
Hey all.

This may be an issue of semantics more than anything, I'm not sure.

Say I'm using the FileSystemObject to loop through a folder full of Excel
files using "For Each ... Next". On every iteration, I'm setting a

Workbook
object using the code "Set objWB = objXL.Workbooks.Open(strFolderPath &
objFile.Name)".

Is it better for me to close each wokbook within the loop (there could be
upwards of 500 workbooks), or close the workbook once, after the loop? In
either case, I will set the variable to nothing after the loop.

In other words, which is better (or is there a difference) -

OPTION A:

For Each objFile In objFolder.Files
Set objWB = objXL.Workbooks.Open(strFolderPath & objFile.Name)
' Do stuff
objWB.Saved = True
objWB.Close
Next
Set objWB = Nohing

OPTION B:

For Each objFile In objFolder.Files
Set objWB = objXL.Workbooks.Open(strFolderPath & objFile.Name)
' Do stuff
Next
objWB.Saved = True
objWB.Close
Set objWB = Nohing

--
Hmm...they have the Internet on COMPUTERS now!



  #4   Report Post  
Posted to microsoft.public.excel.programming
MDW MDW is offline
external usenet poster
 
Posts: 117
Default Programming With Multiple Excel Workbook Objects

Alright, thanks.

Yeah, I wasn't QUITE sure if setting the variable to Nothing would close
those workbooks or not. For some reason I was under the impression that it
did. No idea. *shrugs*

"Bob Phillips" wrote:

I think you may be mixing things up a wee bit in your terminology.

Option 2 only saves closes the last opened workbook, the other 499 are still
open.

Go for option 1, close each down when done with. The Set ... = Nothing is
just releasing the workbook variable from memory, it has nothing to do with
closing.



--

HTH

RP
(remove nothere from the email address if mailing direct)


"MDW" wrote in message
...
Hey all.

This may be an issue of semantics more than anything, I'm not sure.

Say I'm using the FileSystemObject to loop through a folder full of Excel
files using "For Each ... Next". On every iteration, I'm setting a

Workbook
object using the code "Set objWB = objXL.Workbooks.Open(strFolderPath &
objFile.Name)".

Is it better for me to close each wokbook within the loop (there could be
upwards of 500 workbooks), or close the workbook once, after the loop? In
either case, I will set the variable to nothing after the loop.

In other words, which is better (or is there a difference) -

OPTION A:

For Each objFile In objFolder.Files
Set objWB = objXL.Workbooks.Open(strFolderPath & objFile.Name)
' Do stuff
objWB.Saved = True
objWB.Close
Next
Set objWB = Nohing

OPTION B:

For Each objFile In objFolder.Files
Set objWB = objXL.Workbooks.Open(strFolderPath & objFile.Name)
' Do stuff
Next
objWB.Saved = True
objWB.Close
Set objWB = Nohing

--
Hmm...they have the Internet on COMPUTERS now!




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
Excel 2007: Selecting multiple objects by drawing a selection box panalysis Excel Discussion (Misc queries) 4 April 2nd 23 07:41 PM
How does one select multiple drawn objects in Excel 2007? JakeA Excel Discussion (Misc queries) 1 March 8th 08 03:58 PM
Referencing between two Excel Workbook Objects Stephen Schroeder Excel Worksheet Functions 0 July 16th 07 02:08 AM
how to delete multiple autoshape or objects in excel ron Excel Discussion (Misc queries) 4 January 26th 06 11:01 PM
delete multiple autoshapes or objects in excel ron Excel Discussion (Misc queries) 3 January 26th 06 03:01 PM


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