PDA

View Full Version : Solved: Using .Calculate for 1 Workbook



Cyberdude
10-03-2006, 02:00 PM
I have a problem that I'm hoping will be solved by using the ".Calculate" method. When I read Help about .Calculate, it says that I can use it to:
1. Calculate a range, or
2. Calculate a sheet, or
3. Calculate ALL open workbooks.

What I would like to do is calculate a single workbook when it is opened (not ALL workbooks that happen to be open at the time). Can a single-workbook calculate be done? If it can be done, how do I do it?

mvidas
10-03-2006, 02:07 PM
Hi Sid,

Not in one line, but you can always iterate through the sheets. You could also create a function if you'll be doing this multiple times (change as needed):Function CalculateWB(WB As Workbook) As Boolean
If WB Is Nothing Then Exit Function
Dim WS As Worksheet
For Each WS In WB.Worksheets
WS.Calculate
Next
End FunctionMatt

makako
10-03-2006, 02:08 PM
by calculating each sheet in the workbook_open sentence.

for i = 1 to activeworkbook.sheets.count
activeworkbook.sheets(i).calculate

Cyberdude
10-03-2006, 02:57 PM
Thanks, guys. Similar solutions ... both ought to work. Now why didn't I think of that? I guess I was hoping for a single-statement solution, but your suggestions are a good substitute. In fact it's a better way to do it, because I can reduce the amount of calculation to just where I need it in the book. Thanks again. :bow: