Technical Issues - Report Generator Tutorial III  - MS Word

The Report Generator produces high quality documents, but some requirements exceed its capabilities. We considered this issue upon receiving a contract with one column in Russian and the other in English. In such cases it is preferable to create documents in Microsoft Word. From the point of view of the end-user, say a QA lab technician, the process is seamless since Word is under control of FilmStar BASIC and the user need not know that Word is being utilized.

In other words, despite what appears at first glance to be complicated, when it comes to actual usage a technician need only click one button to scan and print a professional QA report.

Examine this Word document. The FilmStar Report Generator would have difficulty with the table containing mixed fonts. This example can be downloaded from Unzip *.bas files to c:\Winfilm\Basic32,  MeasureQA.doc to c:\Winfilm\Word 2010, QA-Word-PE2.scw (for Mpe983.exe) to c:\Winfilm\Measure. If using another MEASURE version, configure %T from 400-800 x 5 nm. Enable Test Mode.

1. Create Word document: After creating the document, field codes (search Word help) are utilized to insert text. The most important field code for our purpose is DOCVARIABLE. By setting .Variables("NAME") = "William F. Cody" in FilmStar BASIC code, Word will replace DOCVARIABLE NAME with "William F. Cody". In the screen shot below we use labels (NAME, PARTID, RANGE1, etc.) that will be part of our field codes.

Graph goes here indicates position of bookmark Graph

2. Insert field codes: Field codes are added (Word 2010) in the Insert menu tab by clicking Quick Parts.. Field. Replace labels with the actual field code, e.g. RANGE1 is replaced by


Alternatively <Ctrl+F9> inserts curly field brackets. Right-click within brackets and hit Edit Field... <Shift+F9> toggles a field code off and on, while <Alt+F9> toggles all field codes.

Inserting field codes in older versions of Word is essentially the same. In Word 2000 click Insert.. Field. <Ctrl+F9> inserts an empty field but right-clicking is not as useful.

There are a large number of field codes, but we are only using DocVariable.

Once labels are replaced by actual field codes the document resembles the following:

<Alt+F9> toggles all field codes on and off. They gray areas indicate that entries are field codes and do not appear when printed.

3. Bookmark graph location(s): In our example, an FSPlot graph is saved (Sub PlotSave) as temp.wmf. This is then utilized in Word's .InlineShapes.AddPicture command. A bookmark sets the range where the picture will be rendered. Referring to the screen shot at the top of this page, we place bookmark Graph at the position denoted by Graph goes here. This is accomplished with Insert.. Bookmark.

Where's the bookmark? According to Microsoft, "1.Click the Word File tab and then click Options. 2.Click Advanced, and then select the Show bookmarks check box under Show document content. 3.Click OK." As indicated below it appears as an I-beam.

Some comments on FilmStar BASIC code MeasureQA_Word.bas.

Kill TmpDir & "temp.wmf"
GraphSetup: PlotActivate: PlotNext: PlotSave TmpDir & "temp"
Wait 1: PlotClose

Here we activate FSPlot, plot the data and save it. Note the Wait statement. Without such delays hang-ups are inevitable. We think this point is sometimes missed and suggest it is the reason instruments such as Cary 2300-2400 series and PE Lambda 4/6 only work with very old slow computers.

With dWord.ActiveDocument
    .Variables("NAME").Value = dName$
    .InlineShapes.AddPicture TmpDir & "temp.wmf", _
       False, True, .Bookmarks("Graph").Range
    ' etc.
End With

Once a reference is established to MS Word (dWord.ActiveDocument), we are really running Word VBA from FilmStar BASIC. That's where Word commands are documented, not in FilmStar help. But you do not have to leave FilmStar BASIC to get the syntax and paste commands. Click Debug.. Browse or the Browse Object icon to bring up the following dialog: