Presentation is loading. Please wait.

Presentation is loading. Please wait.

Similar presentations


Presentation on theme: ""— Presentation transcript:

183 User’s Guide to the ‘QDE Toolkit Pro’
Ch 14: 183 May 2, 2002 National Research Conseil national Council Canada de recherches User’s Guide to the ‘QDE Toolkit Pro’ Excel Tools for Presenting Metrological Comparisons by B.M. Wood, R.J. Douglas & A.G. Steele Chapter 14. Modifying and Adding to the QDE Toolkit Pro The QDE Toolkit Pro is written in Visual Basic for Applications (VBA), which is included as part of your Excel (since Excel ‘95). In this chapter we show just enough of the VBA system to help you judge whether or not you, or a Visual Basic programmer, should try using VBA to customize the Toolkit for your particular purposes. All regular Excel features can be used, and Excel’s macro recording facility is another possibility for customizing the QDE Toolkit Pro.

184 QDE Toolkit Pro - VBA and the Source Code
Ch 14: 184 QDE Toolkit Pro - VBA and the Source Code The Programming Language The QDE Toolkit Pro is written in Microsoft’s Visual Basic for Applications (VBA), which has been included as part of Excel since Excel ‘95. Excel’s macro recorder writes VBA code. The QDE Toolkit Pro consists of about lines of VBA code and comments. The Licence The source code for the QDE Toolkit Pro is provided so that you can freely inspect it, run validation tests on it, and modify it if you wish. It is copyrighted by NRC, but our intention is that it may be freely used, in whole or in part, in all work that acknowledges it and is, in its turn, freely distributed under the same simple conditions (“copyleft”). The Data Storage In ordinary use, the QDE Toolkit Pro macros do not save any variables except on Excel worksheets, so its macros can be used intuitively in many different ways, and in workbooks of arbitrary complexity. The one exception is hidden in module QDE_Toolkit_PlotBuilder, where a subprogram has had to be split.

185 QDE Toolkit Pro - VBA and the Source Code
Ch 14: 185 QDE Toolkit Pro - VBA and the Source Code The VBA source code is included in the Excel workbook QDE2.xls as five VBA modules. Let’s see how to view and edit them... One copy of Excel, having Open Excel Workbooks: QDE Toolkit Pro 2.07 Workbook QDE2.xls Your Excel Workbook, eg CCEMK8.xls Your Excel Workbook, eg another.xls Excel Worksheets: TK Title 100-10 Excel Worksheets: TK Title Anyname1 Anyname2 Anyname3 Sheet1 Sheet2 Sheet3 Sheet4 Sheet5 ... VBA Modules QDE_Toolkit_Functions2 QDE_Toolkit_Macros2 QDE_Toolkit_PlotBuilder QDE_Toolkit_Plots QDE_Toolkit_RV DLLs (in C:\QDE2\ ) MCMedian.dll, MCMedianH.dll, DFORRT.DLL, DFORMD.DLL and MSVCRT.DLL Excel Worksheets: TK Title Input Data

186 QDE Toolkit Pro - VBA and the Source Code
Ch 14: 186 QDE Toolkit Pro - VBA and the Source Code The VBA ‘Programming Language Environment’ or “Editor” To try the VBA Editor, use Tools|Macro|Visual Basic Editor to start VBA Maximize the VBA Editor window. The “Project Explorer” window lets you double-click to choose which ‘module’ of VBA code you have in the Editing window the macro on top you would be listed in the Excel list of macros, and the one on the bottom would not - but would be called from an Excel-listed macro.

187 QDE Toolkit Pro - VBA and the Source Code
Ch 14: 187 QDE Toolkit Pro - VBA and the Source Code To browse the QDE Toolkit Pro with the VBA Editor, start the VBA editor from Excel (previous page) that has a DISCARDABLE COPY of QDE2.xls open. (here it is QDE2a.xls). If you don’t recognize the Project Explorer or VBA Editor windows, try this: Maximize the VBA window. Close any internal windows that you don’t recognize. Click View|Project Explorer, then Click View|Code The two important windows should now be open. If necessary, expand the Modules folder to show all the modules

188 QDE Toolkit Pro - VBA and the Source Code
Ch 14: 188 QDE Toolkit Pro - VBA and the Source Code This copy of Excel has two Excel worksheets open: QDE2a.xls (which has 5 modules of VBA code) and TK_Guide2.xls which has no VBA modules. Some parts of the VBA Code will be familiar to any BASIC programmers. Other elements are new, for example Dim TableRange as Range which declares TableRange to be an Excel-specific Range of Cells on a worksheet. The nomenclature TableRange.Columns(1).Column is typical of the syntax of VBA TableRange.Columns(1) refers to the first (leftmost) column of TableRange, and TableRange.Columns(1).Column refers to the number of that column in the Excel worksheet. Tip: if you want to program in VBA something that you know how to do in Excel, turn on Excel’s macro recorder, perform the desired action, stop recording and find the new Macro1 VBA code with the VBA editor. Next we will scroll up to the top of this module (QDE_Toolkit_Macros2).

189 QDE Toolkit Pro - VBA and the Source Code
Ch 14: 189 QDE Toolkit Pro - VBA and the Source Code Near the beginning of the VBA code for each module of the QDE Toolkit Pro, we have placed an index of the VBA subprograms and functions in the module. Tip: In running a macro, if VBA has an error (for example, trying to clear only part of merged cells) you can select Debug on the error report and see what VBA was executing when it found the error. To clear the error, use Reset. To return to Excel you can use… To find the code for a particular Excel macro or VBA subprogram or function, it if fastest to select the name of the subprogram, and click on th binoculars or use Control-F to start a Find operation for the selected text.

190 QDE Toolkit Pro - VBA and the Source Code
Ch 14: 190 QDE Toolkit Pro - VBA and the Source Code To find the code for a particular Excel macro or VBA subprogram or function, it if fastest to select the name of the subprogram, and click on th binoculars or use Control-F to start a Find operation for the selected text. After two clicks on Find Next, we have found the start of the module. Tip: Another way is to “Page Up” or “Page Down” through the VBA code of the module, while watching the Procedure Name (which displays the procedure name where the editor’s cursor is situated).

191 QDE Toolkit Pro - VBA and the Source Code
Ch 14: 191 QDE Toolkit Pro - VBA and the Source Code This is typical of the VBA code. A significant amount of the VBA code concerns itself with the very rich formatting that is available in Excel. Often the code has more comments than this, and often the code is not as pretty in its physical layout. Editing changes you make here are effective the next time the edited macro is run in Excel. There are quite a few good books on Excel and VBA. GOOD LUCK!!

192 QDE Toolkit Pro - running the Toolkit from Excel’s VBA Toolbar
Ch 14: 192 QDE Toolkit Pro - running the Toolkit from Excel’s VBA Toolbar We find it very convenient to run the QDE Toolkit Pro macros from Excel using Excel’s VBA toolbar. Compared to the Tools|Macro|Macros method outlined earlier, it only saves two mouse clicks per macro, but the macros seem more accessible to us. The disadvantage of this method is that it occupies some precious Toolbar space that you might prefer to dedicate to other uses. Right-click on the blank toolbar background. Click on Visual Basic, and the VBA toolbar appears (you may want to drag it into position). Now one click on the left VBA button launches the Excel macro window where the QDE Toolkit Pro macros can be selected and run.


Download ppt ""

Similar presentations


Ads by Google