A B C D E F G H
1 Example no.2 - Using two different libraries AFinScript © AFIN 2016
2 Start: [F5] or [Ctrl+Q]
3 <<< Parameters   Info: 5 columns (A:E = 'COCPI..T') from the #11 row are reserved for the AFinScript's program.
4 e.g. Path = C:\AnyPath      
5 e.g. Database =        
6 e.g. Period =        
7 My value = 7      
8          
9          
10 Class (Vendor) Object Command Parameters Info The rest: Comments, calculations, row parameters
11 # This example is more complicated. It uses TWO DIFFERRENT libraries to do the task: Calculate something with the macro in a file currently closed and write the calculated value into another Excel file. .
12 .       .
13 # 1. step you have to CALCULATE something. The inicial value is here, in 'B7'. But the alghoritm is in a macro. File: MyVbaMacros.xlsm
The lines below are beeing shown twice: 1. as a value, 2. as a formula calculating this value.
(A char "x" at the begininnig of the formula is for technical reasons only)
.
14 Afin.VBA C:\AnyPath\MyVbaMacros.xlsm SQUARED Arg1=7; PasteTo=MySheet1!A1 0,003 The function SQUARED calculated a value 49
14 Afin.VBA The formula of the cell above:
=""&$B$4&"\MyVbaMacros.xlsm"
SQUARED The formula of the cell above:
="Arg1="&$B$7&"; PasteTo=MySheet1!A1"
0,003 and inserted it into a range specified.
15 # 2. step - we need open an another Excel file 'MyReport.xlsx'… .
16 Afin.ExcelObjects MyReport.xlsx Open a workbook Path=C:\AnyPath 0,003
16 Afin.ExcelObjects MyReport.xlsx Open a workbook The formula of the cell above:
="Path="&$B$4&""
0,003
17 # ...than insert there the value… .
18 Afin.ExcelObjects MyReport.xlsx Set a value Sht=Sheet1; Rng=A1; Value=49 0,003
18 Afin.ExcelObjects MyReport.xlsx Set a value The formula of the cell above:
="Sht=Sheet1; Rng=A1; Value="&MySheet!A1&""
0,003
19 # ...and save and close the file. .
20 Afin.ExcelObjects MyReport.xlsx Save a workbook   0,003
21 Afin.ExcelObjects MyReport.xlsx Close a workbook   0,003
22 0,000
24
25
26 Note: The file 'C:\AnyPath\MyVbaMacros.xlsm' will be automatically closed AFTER ending the script (as all the macro files automatically opened).