Microsoft Excel provides a wonderful environment for exploring the WEAP API, using its Visual Basic Editor. In Excel, first create a new blank workbook, then go to Tools, Macros, Visual Basic Editor (Excel 2007) or Developer, Visual Basic (Excel 2010). (For Excel 2010, commands that you use to edit and run macros are found in the Code group of the Developer tab, which is hidden by default. To make the Developer tab visible, do the following: 1.Click the File tab, and then click Options. 2.Click the Customize Ribbon category. 3.Under Customize the Ribbon, in the Main Tabs list on the right, click Developer, and then click OK.)
Once you are in the Excel Visual Basic Editor, go to Tools, References. Scroll down to find "WEAP API" and make sure the check box is checked. You will only need to do this once for each workbook. Go to View, Immediate Window to open the "Immediate" window, a place for you to type in commands and see their results instantly. Try to following in the Immediate Window, one at a time:
Set W = CreateObject("WEAP.WEAPApplication") ' This will open WEAP and set the local variable W to reference it
? W.Areas.Count ' how many areas do you have? The question mark is VB shorthand for PRINT
W.ActiveArea = "Weaping River Basin" ' open it
W.View = "Data"
W.ActiveScenario = "Current Accounts"
W.Branch("\Demand Sites\South City").Variables("Consumption").Expression = 20
W.LoadFavorite("Groundwater Storage") ' it will calculate at this point
W = nil ' This will close WEAP without saving any changes
Excel can also remind you what are the properties, methods and classes in the WEAP API, via its "Intellisense" technology. Intellisense only works when editing a macro, not in the Immediate Window. On the left side of the Excel Visual Basic Editor, double click on "ThisWorkbook" to open the code window. Then on the menu, choose Insert, Procedure. Give it a name ("Test"), and you can now start adding code to it. On the first line, type
Dim W As
After you type "As" and a space, Excel should pop up a list from which to choose. You can either scroll down to choose WEAPApplication, but it's easier to start typing. After you type WE, Excel should jump to that section of the list. Press the down arrow once to highlight WEAPApplication, then hit Enter to select it. For this to work, you must have already done the Tools, References step mentioned above. (If Excel isn't showing this list, hit Ctrl-space to pop it up.)
Now that Excel knows that W is of type WEAPApplication, you can type W. (that's W followed by a period) and a list will pop up of all the WEAP API properties and methods for the WEAPApplication class. On the next line, type W. and choose ActiveArea from the list. Excel will move to the next line, but that line is not finished yet. Go back up to the W.ActiveArea line and type = "Weaping River Basin" to finish it.
Another way that Excel can show the details of the API is in the "Object Browser." On the menu, choose View, Object Browser. In the top left of this window, change from <All Libraries> to WEAP. Now, you should see all the classes listed on the left. Click on a class, and its properties and methods will be listed on the right. Click on the property or method on the right and information about it will be displayed below. For example, click on WEAPApplication on the left, then ResultValue on the right. Below, you should see all the parameters that ResultValue needs, including which are optional.