Consulting

Results 1 to 4 of 4

Thread: Solved: Using .Calculate for 1 Workbook

  1. #1

    Solved: Using .Calculate for 1 Workbook

    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?

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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):[vba]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 Function[/vba]Matt

  3. #3
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    by calculating each sheet in the workbook_open sentence.

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

  4. #4
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •