Tech Note 610 How to Refresh All Functions in ActiveFactory Workbook All Tech Notes, Tech Alerts and KBCD documents and software are provided "as is" without warranty of any kind. See the Terms of Use for more information. Topic#: 002366 Created: May 2009 Updated: May 2011 Introduction In ActiveFactory Workbook, the array size of a function does not automatically resize when cells recalculate. The refresh function provided by the ActiveFactory workbook library provides a routine that will automatically resize an array for you. This technote provides an example on how to run a macro to refresh all functions within a workbook. Application Versions Solution ActiveFactory Workbook 9.0 and later. Microsoft Excel 2007 and later. 1. Open Excel. Use the new workbook as a template. With MS Excel 2007, you must enable the Developer tab to insert buttons. 2. Click the Medallion (upper left) and click Excel Options (Figure 1 below). https://wdnresource.wonderware.com/support/kbcd/html/1/t002366.htm 1/5
FIGURE 1: CLICK EXCEL OPTIONS 3. Click the Show Developer Tab in the Ribbon option. https://wdnresource.wonderware.com/support/kbcd/html/1/t002366.htm 2/5
FIGURE 2: ENABLE THE DEVELOPER TAB IN MICROSOFT EXCEL 2007 FROM EXCEL OPTIONS 4. Click OK to save your changes. 5. From the main menu, click Developer > Insert > Form Controls. Insert a Button Form control that will be used to refresh all functions (Figure 3 below). FIGURE 3: INSERT A BUTTON FORM CONTROL ONTO THE WORKSHEET 6. After adding a button to the form, you are prompted to assign a new macro to this button. 7. Click New to assign the new macro. 8. Add the following code to the workbook source as shown in Figure 4 (below): Sub RefreshAllFormulas() Dim i As Integer Dim CurCell As Object Dim lastcellfx As Object MousePointer = fmmousepointerhourglass https://wdnresource.wonderware.com/support/kbcd/html/1/t002366.htm 3/5
Total = 0 For i = 1 To ActiveWorkbook.Sheets.Count Subtotal = 0 On Error Resume Next Sheets(i).Activate Selection.SpecialCells(xlCellTypeFormulas, 23).Select For Each CurCell In Selection If lastcellfx.formula <> CurCell.Formula Then CurCell.Activate mnurefreshselection Set lastcellfx = CurCell End If Next CurCell Next i MousePointer = fmmousepointerdefault Sheets(1).Activate End Sub FIGURE 4: VB SCRIPT EDITOR Note: Do not call the mnurefreshselection function from the SheetCalculate Event in order to automate this function. Doing so within Excel creates a Race Condition (infinite calculation loop). 6. With the macro for the button, add the line to call this function RefreshAllFormulas. 7. In the VBA editor, click Tools/References. 8. Browse for the reference ActiveFactoryWorkbook and click it. https://wdnresource.wonderware.com/support/kbcd/html/1/t002366.htm 4/5
FIGURE 5: VBAPROJECT REFERENCES 8. Click OK to save your changes and close the editor. Now whenever you make dynamic changes to the start- and end time of a function, you can click on the button you created in order to resize all arrays. Click the following icon to view this file in.pdf format: C. Azer Tech Notes are published occasionally by Wonderware Technical Support. Publisher: Invensys Systems, Inc., 26561 Rancho Parkway South, Lake Forest, C A 92630. There is also technical information on our software products at Wonderware Technical Support. For technical support questions, send an e-mail to support@wonderware.com. Back to top 2013 Invensys Systems, Inc. All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any form or by any means, electronic or mechanical, including photocopying, recording, broadcasting, or by anyinformation storage and retrieval system, without permission in writing from Invensys Systems, Inc. Terms of Use. https://wdnresource.wonderware.com/support/kbcd/html/1/t002366.htm 5/5