home *** CD-ROM | disk | FTP | other *** search
/ Chip: 25 Years Anniversary / CHIP_25Jahre_Jubilaeum.iso / downloads / 401065 / WPO11 / Data1.cab / _712313E9AF8142FE82DAE4BE2F7A562D < prev    next >
Text File  |  2003-03-07  |  26KB  |  1,094 lines

  1. Global Macros
  2.  
  3. Global macros can be executed in all WordPerfect documents. Global macros are stored in a special file called WordPerfect11.GMS. All objects that are used by a Global macro are also stored in the WordPerfect11.GMS. For example, if a macro uses a form, then the form is stored in the WordPerfect11.GMS.
  4.  
  5. To create a VBA global macro
  6.  
  7. 1.    Click Tools, Visual Basic, Visual Basic Editor.
  8.  
  9. 2.    Double-click on Global Macros in the Project view.
  10.  
  11. 3.    Click Insert, User Form.
  12.  
  13. 4.    Change the form so that it resembles the following diagram:
  14.  
  15.  
  16.  
  17. 5.    Change the name of the TextBox control to NameBox as illustrated in the following list:
  18.  
  19. Command Button - CommandButton1
  20.  
  21. TextBox - NameBox
  22.  
  23. You can change all of the control's attributes, including the name of the control, in the Property dialog box located in the Visual Basic Editor.
  24.  
  25. 6.    Double-click the CommandButton1 control to create a new method for the UserForm1 class, then type the following lines of code in the CommandButton1_Click method:
  26.  
  27. Private Sub CommandButton1_Click()
  28.  
  29.  Dim myname, Msg As String
  30.  
  31.  myname = NameBox
  32.  
  33.  Msg = "Hello " & myname
  34.  
  35.  MsgBox Msg
  36.  
  37.  End
  38.  
  39. End Sub
  40.  
  41. This code responds to the event that occurs when the command button is clicked.
  42.  
  43. 7    Double-click the WordPerfect Objects folder in the Project view.
  44.  
  45. 8.    Double-click ThisDocument, then type the following lines of code in the Editor window:
  46.  
  47. Public Sub ShowForm()
  48.  
  49. End Sub
  50.  
  51. This code will add a new method to the ThisDocument class. If you declare ShowForm as a Private method, you will not be able to run it from WordPerfect.
  52.  
  53. 9.    Type the following line of code in the ShowForm method:
  54.  
  55. Public Sub ShowForm()
  56.  
  57.  UserForm1.Show
  58.  
  59. End Sub
  60.  
  61. Note
  62.  
  63.   The name of this macro is ShowForm. The name of the form is UserForm1, which is the default name. UserForm1, along with this macro would be stored in WordPerfect11.GMS.
  64.   
  65. WordPerfect VBA Events
  66.  
  67. Visual Basic for Applications is an event-driven programming language. Most of the code you create is written to respond to an event. An event is an action that is recognized by VBA; for example, clicking a button or choosing an option from a list box. Unlike traditional procedural programming, in which the program starts at line 1 and executes line by line, event-driven programming executes code in response to events.
  68.  
  69. WordPerfect document events can be broken down into two categories: Global and Project. A Global event is recognized by all WordPerfect documents. For example, if you create a VBA macro in the AfterOpen event, this macro is valid for any WordPerfect document. In contrast to Global events there are Project events. A Project event is only recognized by the local document. Project events are members of the Document class. The name of the object is the same as the class. 
  70.  
  71. Global events are members of the GlobalMacros class. The name of the object is the same as the class. Global macros are stored in a special file named WordPerfect11.GMS. All global events are stored in the WordPerfect11.GMS file. 
  72.  
  73. Events in WordPerfect are code placeholders. It is up to you to code the response. Events are called in response to a specific action. When an action calls an event, the code located within the event is executed. You can create simple or complex events. You can code a single line that displays a Message Box or write an entire procedure that interacts with a database. 
  74.  
  75. Global Events
  76.  
  77.     BeforeNew()
  78.  
  79.     AfterNew()
  80.  
  81.     BeforeClose()
  82.  
  83.     AfterClose()
  84.  
  85.     BeforeSwitchDocument()
  86.  
  87.     AfterSwitchDocument()
  88.  
  89.     BeforeTables()
  90.  
  91.     AfterTables()
  92.  
  93.     BeforeOpen()
  94.  
  95.     AfterOpen()
  96.  
  97.     BeforePrint()
  98.  
  99.     AfterPrint()
  100.  
  101.     BeforeSave()
  102.  
  103.     AfterSave()
  104.  
  105.     AfterStartup()
  106.  
  107.  
  108.  
  109. Project Events
  110.  
  111.     BeforeOpen()
  112.  
  113.     AfterOpen()
  114.  
  115.     BeforePrint()
  116.  
  117.     AfterPrint()
  118.  
  119.     BeforeTables()
  120.  
  121.     AfterTables()
  122.  
  123.     BeforeSave()
  124.  
  125.     AfterSave()
  126.  
  127.     BeforeClose()
  128.  
  129. Document.BeforeOpen()
  130.  
  131. Syntax
  132.  
  133. Private Sub Document_BeforeOpen()
  134.  
  135. Description
  136.  
  137. This event is called when you open a document. The code in the event is executed before the document appears.
  138.  
  139. Example
  140.  
  141. In the code fragment below, a Message Box appears which displays the time and date. This data can be written to a database that keeps track of file activities.
  142.  
  143. Private Sub Document_BeforeOpen()
  144.  
  145. '*** Declare all variables
  146.  
  147. Dim myTime
  148.  
  149. Dim myDate As Date
  150.  
  151. Dim myStrTime, myStrDate, Msg As String
  152.  
  153.  
  154.  
  155. '**** Populate the variables
  156.  
  157. myTime = Time
  158.  
  159. myDate = Date
  160.  
  161.  
  162.  
  163. myStrDate = Str(myDate)
  164.  
  165. myStrTime = Str(myTime)
  166.  
  167.  
  168.  
  169. '*** Display the Message Box
  170.  
  171. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  172.  
  173. MsgBox Msg
  174.  
  175. End Sub
  176.  
  177. Note
  178.  
  179.   The Message Box will appear before the document is opened. After the Message Box is closed, the document will open. 
  180.   
  181. Document.AfterOpen()
  182.  
  183. Syntax
  184.  
  185. Private Sub Document_AfterOpen()
  186.  
  187. Description
  188.  
  189. This event is called as soon as an existing document opens. 
  190.  
  191. Example
  192.  
  193. You can customize your document by inserting a watermark. You can insert a watermark into every odd page of your document by coding the following into the AfterOpen() event:
  194.  
  195. Private Sub Document_AfterOpen()
  196.  
  197. PerfectScript.ClearDoc
  198.  
  199. PerfectScript.WatermarkA Create_WatermarkA_Action, OddPages_WatermarkA_Occurrence
  200.  
  201. PerfectScript.BoxCreate 6
  202.  
  203. PerfectScript.BoxContentType Image_BoxContentType_Content
  204.  
  205. PerfectScript.BoxImageRetrieve MakeInternal_BoxImageRetrieve_Action, "C:\rose2.wpg"
  206.  
  207. PerfectScript.ChangeWatermarkGraphicShade 25
  208.  
  209.  
  210.  
  211. PerfectScript.BoxUpdateDisplay
  212.  
  213. PerfectScript.BoxEnd Save_BoxEnd_State
  214.  
  215. PerfectScript.Close
  216.  
  217. End Sub
  218.  
  219. Note
  220.  
  221.   You need a graphic file for this procedure. The name of this file is:ROSE2.WPG. This file is located in the "C:\Corel\WordPerfect Office 2002\graphics\clipart\basic clipart" folder. It is recommended that you place this file in the C:\.
  222.   
  223. Document.AfterPrint()
  224.  
  225. Syntax
  226.  
  227. Private Sub Document_AfterPrint()
  228.  
  229. Description
  230.  
  231. This event is called after you print your document.
  232.  
  233. Example
  234.  
  235. You can inform the user that the document is printed by coding a Message Box.
  236.  
  237. Private Sub Document_AfterPrint()
  238.  
  239. MsgBox ("You have just printed this document")
  240.  
  241. End Sub
  242.  
  243. Document.BeforePrint()
  244.  
  245. Syntax
  246.  
  247. Private Sub Document_BeforePrint()
  248.  
  249. Description
  250.  
  251. This event is called when you send a document to the printer. This enables you to customize your document before it is printed.
  252.  
  253. Example
  254.  
  255. You can call a form which displays an image.
  256.  
  257. Private Sub Document_BeforePrint()
  258.  
  259.  
  260.  
  261. '******* Call the Form
  262.  
  263. FallsForm.Show
  264.  
  265. End Sub
  266.  
  267.  
  268.  
  269. Note
  270.  
  271.   FallsForm is a VBA Form which contains an image control.
  272.   
  273. Document.AfterSave()
  274.  
  275. Syntax
  276.  
  277. Private Sub Document_AfterSave()
  278.  
  279. Description
  280.  
  281. This event is called after you save your document.
  282.  
  283. Example
  284.  
  285. You can create a message box that displays the time and date. This data can be stored to a database which keeps track of file activities.
  286.  
  287. Private Sub Document_AfterSave()
  288.  
  289. '*** Declare all variables
  290.  
  291. Dim myTime
  292.  
  293. Dim myDate As Date
  294.  
  295. Dim myStrTime, myStrDate, Msg As String
  296.  
  297.  
  298.  
  299. '**** Populate the variables
  300.  
  301. myTime = Time
  302.  
  303. myDate = Date
  304.  
  305.  
  306.  
  307. myStrDate = Str(myDate)
  308.  
  309. myStrTime = Str(myTime)
  310.  
  311.  
  312.  
  313. '*** Display the Message Box
  314.  
  315. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  316.  
  317. MsgBox Msg
  318.  
  319. End Sub
  320.  
  321. Document.BeforeSave()
  322.  
  323. Syntax
  324.  
  325. Private Sub Document_BeforeSave()
  326.  
  327. Description
  328.  
  329. This event is called when you save the document. This enables you to customize your document before you save it.
  330.  
  331. Example
  332.  
  333. In the following example, the zoom setting is changed to page view each time the document is saved. This setting persists until it is changed.
  334.  
  335. Private Sub Document_BeforeSave()
  336.  
  337. PerfectScript.ZoomToFullPage
  338.  
  339. End Sub
  340.  
  341. Document.AfterTables()
  342.  
  343. Syntax
  344.  
  345. Private Sub Document_AfterTables()
  346.  
  347. Description
  348.  
  349. This event is called after you insert a table into your document. This is a useful event to customize tables.
  350.  
  351. Example
  352.  
  353. You can create a macro that will format a table that is inserted into the document. In the following example, the table's border is changed. Add the following to the AfterTables() event:
  354.  
  355. Private Sub Document_AfterTables()
  356.  
  357. PerfectScript.TableBorderEditBegin
  358.  
  359. PerfectScript.TableBorder 5
  360.  
  361. PerfectScript.TableBorderEditEnd Save_TableBorderEditEnd_State
  362.  
  363. End Sub
  364.  
  365. Note
  366.  
  367.   In the above code fragment, the value 5 corresponds to a thick border. All PerfectScript class members that require any for an argument, must have the numeric value passed. 
  368.   
  369. Document.BeforeTables()
  370.  
  371. Syntax
  372.  
  373. Private Document_BeforeTables()
  374.  
  375. Description
  376.  
  377. This event is called before the table appears in your document.
  378.  
  379. Example
  380.  
  381. In the following example, a new form appears that allows the user to select a choice of three border styles. The result is stored in a global variable called g_borderStyle.
  382.  
  383.  
  384.  
  385. Private Sub Document_BeforeTables()
  386.  
  387.  
  388.  
  389. '*** Call the New Form
  390.  
  391. UserForm1.Show
  392.  
  393. g_borderStyle = UserForm1.myBorder
  394.  
  395. End Sub
  396.  
  397. Note
  398.  
  399.   You can pass g_borderStyle to the PerfectScript.TableBorder()
  400.   
  401. Document.BeforeClose()
  402.  
  403. Syntax
  404.  
  405. Private Sub Document_BeforeClose()
  406.  
  407. Description
  408.  
  409. This event is called when you close the document; however, this code is executed before the document is actually closed.
  410.  
  411. Example
  412.  
  413. You can create a message box that informs the user that the document will close. The message box will appear before the document is closed.
  414.  
  415. Private Sub Document_BeforeClose()
  416.  
  417. MsgBox "You are about to close this document"
  418.  
  419. End Sub
  420.  
  421. GlobalMacros.BeforeSwitchDocument()
  422.  
  423. Syntax
  424.  
  425. Private Sub GlobalMacros_BeforeSwitchDocument()
  426.  
  427. Description
  428.  
  429. This event is called when you switch documents. The code in this event is executed before the new document appears.
  430.  
  431. Example
  432.  
  433. In the following code fragment, a Message Box appears with the time and date. This data can be stored to a database which keeps track of file activities.
  434.  
  435. Private Sub GlobalMacros_BeforeSwitchDocument())
  436.  
  437. '*** Declare all variables
  438.  
  439. Dim myTime
  440.  
  441. Dim myDate As Date
  442.  
  443. Dim myStrTime, myStrDate, Msg As String
  444.  
  445.  
  446.  
  447. '**** Populate the variables
  448.  
  449. myTime = Time
  450.  
  451. myDate = Date
  452.  
  453.  
  454.  
  455. myStrDate = Str(myDate)
  456.  
  457. myStrTime = Str(myTime)
  458.  
  459.  
  460.  
  461. '*** Display the MessageBox
  462.  
  463. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  464.  
  465. MsgBox Msg
  466.  
  467. End Sub
  468.  
  469.  
  470.  
  471. GlobalMacros.AfterSwitchDocument()
  472.  
  473. Syntax
  474.  
  475. Private Sub GlobalMacros_AfterSwitchDocument()
  476.  
  477. Description
  478.  
  479. This event is called after you switch documents. In contrast to BeforeSwitchDocument, this event is executed after the new document appears.
  480.  
  481. Example
  482.  
  483. In the following code fragment, a Message Box appears with the time and date. This data can be stored to a database which keeps track of file activities.
  484.  
  485. Private Sub GlobalMacros_AfterSwitchDocument()
  486.  
  487. '*** Declare all variables
  488.  
  489. Dim myTime
  490.  
  491. Dim myDate As Date
  492.  
  493. Dim myStrTime, myStrDate, Msg As String
  494.  
  495.  
  496.  
  497. '**** Populate the variables
  498.  
  499. myTime = Time
  500.  
  501. myDate = Date
  502.  
  503.  
  504.  
  505. myStrDate = Str(myDate)
  506.  
  507. myStrTime = Str(myTime)
  508.  
  509.  
  510.  
  511. '*** Display the MessageBox
  512.  
  513. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  514.  
  515. MsgBox Msg
  516.  
  517. End Sub
  518.  
  519.  
  520.  
  521. GlobalMacros.BeforeNew()
  522.  
  523. Syntax
  524.  
  525. Private Sub GlobalMacros_BeforeNew()
  526.  
  527. Description
  528.  
  529. This event is called when you select a new document; however, the code is executed before the new document appears.
  530.  
  531. Example
  532.  
  533. In the following example, a simple string "Hello" is inserted into the document. The important concept to note is that the text will be entered into the existing document. This will not effect the new document.
  534.  
  535. Private Sub GlobalMacros_BeforeNew()
  536.  
  537. PerfectScript.KeyType "Hello"
  538.  
  539. End Sub
  540.  
  541. GlobalMacros.AfterNew()
  542.  
  543. Syntax
  544.  
  545. Private Sub GlobalMacros_AfterNew()
  546.  
  547. Description
  548.  
  549. This event is called when you select a new document; however, in contrast to BeforeNew() the code is executed after the new document appears.
  550.  
  551. Example
  552.  
  553. In the following example, a simple string "Hello" is inserted into the document. The important concept to note is that the text will be entered into the new document.
  554.  
  555. Private Sub GlobalMacros_AfterNew()
  556.  
  557. PerfectScript.KeyType "Hello"
  558.  
  559. End Sub
  560.  
  561. GlobalMacros.BeforeClose()
  562.  
  563. Syntax
  564.  
  565. Private Sub GlobalMacros_BeforeClose()
  566.  
  567. Description
  568.  
  569. This event is called when you close the document; however, the code is executed before the "Save changes to" dialog box appears.
  570.  
  571. Example
  572.  
  573. In the following example, a form is called which displays an image. The important concept to note is that this image will be displayed before the "Save changes to" dialog box appears.
  574.  
  575. Private Sub GlobalMacros_BeforeClose()
  576.  
  577. '**** Call the new form
  578.  
  579. FallsForm.Show
  580.  
  581. End Sub
  582.  
  583. Note
  584.  
  585.   FallsForm is a VBA Form which contains an image control. You must create a form called FallsForm to implement this example.
  586.   
  587. GlobalMacros.AfterClose()
  588.  
  589. Syntax
  590.  
  591. Private Sub GlobalMacros_AfterClose()
  592.  
  593. Description
  594.  
  595. This event is called when you close the document; however, the code is executed after the "Save changes to" dialog appears.
  596.  
  597. Example
  598.  
  599. In the following example, a new form is called which simply displays an image. This image will appear after the "Save changes to" dialog box appears.
  600.  
  601. Private Sub GlobalMacros_AfterClose()
  602.  
  603. TOForm.show
  604.  
  605. End Sub
  606.  
  607. Note
  608.  
  609.   TOForm is a VBA Form which contains an image control. You must create a form called TOForm to implement this example.
  610.   
  611. GlobalMacros.BeforeOpen()
  612.  
  613. Syntax
  614.  
  615. Private Sub GlobalMacros_BeforeOpen()
  616.  
  617. Description
  618.  
  619. This event is called when you open a document; however, this code is executed before the document appears.
  620.  
  621. Example
  622.  
  623. You can code a message box that displays the time and date. This data can be stored to a database which keeps track of file activities.
  624.  
  625. Private Sub GlobalMacros_BeforeOpen()
  626.  
  627. '*** Declare all variables
  628.  
  629. Dim myTime
  630.  
  631. Dim myDate As Date
  632.  
  633. Dim myStrTime, myStrDate, Msg As String
  634.  
  635.  
  636.  
  637. '**** Populate the variables
  638.  
  639. myTime = Time
  640.  
  641. myDate = Date
  642.  
  643.  
  644.  
  645. myStrDate = Str(myDate)
  646.  
  647. myStrTime = Str(myTime)
  648.  
  649.  
  650.  
  651. '*** Display the Message Box
  652.  
  653. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  654.  
  655. MsgBox Msg
  656.  
  657. End Sub
  658.  
  659. GlobalMacros.AfterOpen()
  660.  
  661. Syntax
  662.  
  663. Private Sub GlobalMacros_AfterOpen()
  664.  
  665. Description
  666.  
  667. This event is called when you open a document; however, this code is executed after the document appears.
  668.  
  669. Example
  670.  
  671. You can customize your document by inserting a watermark as soon as the document opens. You can insert a watermark into every odd page of your document by coding the following into this event:
  672.  
  673. Private Sub GlobalMacros_AfterOpen()
  674.  
  675. PerfectScript.ClearDoc
  676.  
  677. PerfectScript.WatermarkA Create_WatermarkA_Action, OddPages_WatermarkA_Occurrence
  678.  
  679. PerfectScript.BoxCreate 6
  680.  
  681. PerfectScript.BoxContentType Image_BoxContentType_Content
  682.  
  683. PerfectScript.BoxImageRetrieve MakeInternal_BoxImageRetrieve_Action, "C:\rose2.wpg"
  684.  
  685. PerfectScript.ChangeWatermarkGraphicShade 25
  686.  
  687. PerfectScript.BoxUpdateDisplay
  688.  
  689. PerfectScript.BoxEnd Save_BoxEnd_State
  690.  
  691. PerfectScript.Close
  692.  
  693. End Sub
  694.  
  695. Note
  696.  
  697.   You need a graphic file for this procedure. The name of this file is:ROSE2.WPG. This file is located in the "C:\Corel\WordPerfect Office 2002\graphics\clipart\basic clipart" folder. It is recommended that you place this file in the C:\.
  698.   
  699. GlobalMacros.BeforePrint()
  700.  
  701. Syntax
  702.  
  703. Private Sub GlobalMacros_BeforePrint()
  704.  
  705. Description
  706.  
  707. This event is called when you print the document. The code is executed after the "Print to" dialog box is closed, but before the document is sent to the printer.
  708.  
  709. GlobalMacros.AfterPrint()
  710.  
  711. Syntax
  712.  
  713. Private Sub GlobalMacros_AfterPrint()
  714.  
  715. Description
  716.  
  717. This event is called when you print the document. The code is executed after the document is sent to the printer.
  718.  
  719. GlobalMacros.BeforeTables()
  720.  
  721. Syntax
  722.  
  723. Private Sub GlobalMacros_BeforeTables()
  724.  
  725. Description
  726.  
  727. This event is called when you insert a table into the document. This code is executed before the table is inserted into the document.
  728.  
  729. Example
  730.  
  731. In the following example, a new form will appear that will allow the user to select a border style. The user can select one of three styles. The result will be stored in a global variable called g_borderStyle.
  732.  
  733.  
  734.  
  735. Private Sub Document_BeforeTables()
  736.  
  737.  
  738.  
  739. '*** Call the New Form
  740.  
  741. UserForm1.Show
  742.  
  743. g_borderStyle = UserForm1.myBorder
  744.  
  745. End Sub
  746.  
  747. Note
  748.  
  749.   You can pass g_borderStyle to the PerfectScript.TableBorder()
  750.   
  751. GlobalMacros.AfterTables()
  752.  
  753. Syntax
  754.  
  755. Private Sub GlobalMacros_AfterTables()
  756.  
  757. Description
  758.  
  759. This event is called after you insert a table into your document. This is a useful event to customize tables.
  760.  
  761. Example
  762.  
  763. You can create a macro that will format a table that is inserted into the document. In the following example, the table's border is changed. Add the following to the AfterTables() event:
  764.  
  765. Private Sub GlobalMacros_AfterTables()
  766.  
  767. PerfectScript.TableBorderEditBegin
  768.  
  769. PerfectScript.TableBorder 5
  770.  
  771. PerfectScript.TableBorderEditEnd Save_TableBorderEditEnd_State
  772.  
  773. End Sub
  774.  
  775. Note
  776.  
  777.   In the above code fragment, the value 5 corresponds to a thick border. Refer to Product Command Values to obtain the correct integer value.
  778.   
  779. GlobalMacros.BeforeSave()
  780.  
  781. Syntax
  782.  
  783. Private Sub GlobalMacros_BeforeSave()
  784.  
  785. Description
  786.  
  787. This event is called just before the document is saved. This gives you a chance to customize your document before it is saved.
  788.  
  789. Example
  790.  
  791. In the following example, the zoom setting is changed to full page every time the document is saved. This setting will last until it is changed.
  792.  
  793. Private Sub Document_BeforeSave()
  794.  
  795. PerfectScript.ZoomToFullPage
  796.  
  797. End Sub
  798.  
  799. GlobalMacros.AfterSave()
  800.  
  801. Syntax
  802.  
  803. Private Sub GlobalMacros_AfterSave()
  804.  
  805. Description
  806.  
  807. This event is called after you have saved your document.
  808.  
  809. Example
  810.  
  811. In the following code fragment, a Message Box appears with the time and date. This data can be stored to a database which keeps track of file activities.
  812.  
  813. Private Sub GlobalMacros_AfterSave()
  814.  
  815. '*** Declare all variables
  816.  
  817. Dim myTime
  818.  
  819. Dim myDate As Date
  820.  
  821. Dim myStrTime, myStrDate, Msg As String
  822.  
  823.  
  824.  
  825. '**** Populate the variables
  826.  
  827. myTime = Time
  828.  
  829. myDate = Date
  830.  
  831.  
  832.  
  833. myStrDate = Str(myDate)
  834.  
  835. myStrTime = Str(myTime)
  836.  
  837.  
  838.  
  839. '*** Display the Message Box
  840.  
  841. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  842.  
  843. MsgBox Msg
  844.  
  845. End Sub
  846.  
  847. GlobalMacros.AfterStartup()
  848.  
  849. Syntax
  850.  
  851. Private Sub GlobalMacros_AfterStartup()
  852.  
  853. Description
  854.  
  855. This event is called when WordPerfect starts. The code in this event is executed while the splash screen is active.
  856.  
  857. Example
  858.  
  859. You can create a macro that will call a message box asking you if you want a watermark in the WordPerfect document. If you select Yes, then a watermark will be inserted.
  860.  
  861. Private Sub GlobalMacros_AfterStartup()
  862.  
  863. '**** Declare all variables
  864.  
  865. Dim Msg, Style, Title, Response, MyString
  866.  
  867. Msg = "Do you want to insert a watermark?" 
  868.  
  869. Style = vbYesNo + vbQuestion 
  870.  
  871. Title = "WordPerfect"    ' Define title.
  872.  
  873.  
  874.  
  875. Response = MsgBox(Msg, Style, Title)
  876.  
  877. If Response = vbYes Then    
  878.  
  879.     PerfectScript.ClearDoc
  880.  
  881. PerfectScript.WatermarkA Create_WatermarkA_Action, OddPages_WatermarkA_Occurrence
  882.  
  883. PerfectScript.BoxCreate 6
  884.  
  885. PerfectScript.BoxContentType Image_BoxContentType_Content
  886.  
  887. PerfectScript.BoxImageRetrieve MakeInternal_BoxImageRetrieve_Action, "C:\rose2.wpg"
  888.  
  889. PerfectScript.ChangeWatermarkGraphicShade 25
  890.  
  891. PerfectScript.BoxUpdateDisplay
  892.  
  893. PerfectScript.BoxEnd Save_BoxEnd_State
  894.  
  895. PerfectScript.Close
  896.  
  897.  
  898.  
  899. Else    
  900.  
  901.     MsgBox "No watermark will be inserted"    
  902.  
  903. End If
  904.  
  905. End Sub
  906.  
  907. Note
  908.  
  909.   You need a graphic file for this procedure. The name of this file is:ROSE2.WPG. This file is located in the "C:\Corel\WordPerfect Office 2002\graphics\clipart\basic clipart" folder. It is recommended that you place this file in the C:\.
  910.   
  911. Working with product commands that use a Variable
  912.  
  913. You must declare a variable that you pass to a product command as a Variant.
  914.  
  915. Refer to the following code fragment:
  916.  
  917.  
  918.  
  919. '**** Declare the variable
  920.  
  921. Dim myAnswer As Variant
  922.  
  923.  
  924.  
  925. '*** Pass the variable to DirectoryExists()
  926.  
  927. PerfectScript.DirectoryExists myAnswer, "D:\Client"
  928.  
  929. MsgBox myAnswer
  930.  
  931. Code Explanation
  932.  
  933. A Boolean value is returned to myAnswer. If the directory exists, then myAnswer will be assigned the value True. If the directory does not exist, then myAnswer will be assigned False. 
  934.  
  935.  
  936.  
  937. WordPerfect product commands that use Raw Binary Data
  938.  
  939. The following product commands use raw binary data:
  940.  
  941.     ThirdPartyCreate
  942.  
  943.     ThirdPartyFindByID
  944.  
  945. WordPerfect product commands that use WordPerfect unit values
  946.  
  947. There are many product commands which require a WordPerfect unit as an argument. You must calculate any numeric value into a WordPerfect unit. The formula to calculate a WordPerfect unit is:
  948.  
  949. WordPerfect unit = (n*1200), where n is an inch.
  950.  
  951. Note
  952.  
  953.   The easiest way to convert to a WordPerfect unit is to convert all measurements to inches and multiply 1200.
  954.   
  955. WordPerfect product commands that use WordPerfect Codes
  956.  
  957. WordPerfect codes are used by WordPerfect to complete a specific objective. For example, a hyphen is a WordPerfect code. You can check the Reveal Codes for other codes. PerfectScript recognizes WordPerfect codes; however, the VBA compiler does not. The following two product commands use WordPerfect codes:
  958.  
  959. WordPerfect product commands that use WordPerfect Codes:
  960.  
  961.     DateFormat
  962.  
  963.     PrinterCommand
  964.  
  965. Product Commands that use Any
  966.  
  967. You must pass the integer value of any parameter that uses any. The VBA compiler does not recognize the string value. For example, the product command TableBorder() uses any for an argument. You can pass ThinBorder! or ThickBorder! when you are creating macros using PerfectScript. However, when you are using VBA to create macros, you must pass the integer value which corresponds to the style you want. 
  968.  
  969. Product Commands that use Any:
  970.  
  971.     Product command that use Any
  972.  
  973.     Code Example
  974.  
  975.  
  976.  
  977. Working with repeating parameters
  978.  
  979. To use product commands in VBA that have repeating parameters an array must be used. You should declare a variant and assign an array to the variant. Refer to the following code example, which illustrates how to use PreTaskBar:
  980.  
  981. Example 1
  982.  
  983. '***** Create the variables
  984.  
  985. Dim boxes As Variant
  986.  
  987. Dim widths As Variant
  988.  
  989. Dim textIcon As Variant
  990.  
  991.  
  992.  
  993. '****** Populate each array
  994.  
  995. boxes = Array(7, 9, 2, 4, 10, 5)
  996.  
  997. textIcon = Array(0, 0, 0, 0, 0, 0)
  998.  
  999. widths = Array(50, 75, 50, 20, 100, 50)
  1000.  
  1001.  
  1002.  
  1003. '****** Pass each array
  1004.  
  1005. PerfectScript.PrefTaskBar boxes, textIcon, widths
  1006.  
  1007. Example 2
  1008.  
  1009. '****** Pass each array
  1010.  
  1011. PerfectScript.PrefTaskBar Array(7, 9, 2, 4, 10, 5),Array(0, 0, 0, 0, 0, 0),Array(50, 75, 50, 20, 100, 50) 
  1012.  
  1013. Code Explanation
  1014.  
  1015. You must define the box style, the icon style, and the width for every item that you want to appear on the application bar. In the example above, there are six elements in each array, meaning that six items will appear on the application bar. 
  1016.  
  1017. Three variants are created. Each variant is defined as an array, with each element corresponds to the application bar item. The boxes array is populated with the specific box style. All values in the textIcon array are 0, representing icons as opposed to 1 which represents text. The values in the widths array specifies the width of each item. All three variables are passed after they have been populated.
  1018.  
  1019. In the second example, all the arrays are populated during the product command call. The benefit of this method is it decreases the lines of code in your macro.
  1020.  
  1021. Note
  1022.  
  1023.   You must use the integer values when populating an array used for repeating parameters. 
  1024.   
  1025.  
  1026.  
  1027. WordPerfect product commands that are reserved words in VBA
  1028.  
  1029. There are two product commands that are reserved words in VBA. You have to use the VBA equivalent. Refer to the following list:
  1030.  
  1031. Product command        VBA equivalent 
  1032.  
  1033. Type()                KeyType 
  1034.  
  1035. Print()                WPPrint 
  1036.  
  1037. Product commands with repeating parameters
  1038.  
  1039. To use product commands in VBA with repeating parameters, you must declare an array. Values for each repetitive parameter must be loaded into the array. After the array is populated, you have to pass the array.
  1040.  
  1041. Product commands with repeating parameters:
  1042.  
  1043.     Product command that have Repeating Parameters
  1044.  
  1045.     Code Example
  1046.  
  1047. Note
  1048.  
  1049. You must use the integer values when populating an array used for repeating parameters.VBA Programming issues relating to PerfectScript class members
  1050.  
  1051. There are several issues that must be discussed with respect to programming with product commands in the VBA environment. You can click on any of the following for a detailed explanation: 
  1052.  
  1053.  
  1054.  
  1055.     Product commands that use Any
  1056.  
  1057.     Product commands with Repeating Parameters
  1058.  
  1059.     Product commands that require a Variable
  1060.  
  1061.     Product commands that use WordPerfect Codes
  1062.  
  1063.     Product commands that use Raw Binary Data
  1064.  
  1065.     Product commands that are Reserved Words in VBA
  1066.  
  1067.     Product commands that use WordPerfect Units
  1068.  
  1069. WordPerfect product commands that use a VARIABLE as a parameter
  1070.  
  1071. You must use a Variant for any WordPerfect product command that requires a variable as a parameter. The Variant data type is the data type for all variables that are not declared as another specific type. If you do not declare the variable as a Variant, then your VBA macro will not function properly . The following list is all the product commands in WordPerfect which use Variable as a parameter:
  1072.  
  1073. Product commands that use a VARIABLE as a parameter:
  1074.  
  1075.     DirectoryExists
  1076.  
  1077.     FileExists
  1078.  
  1079.     GetAcceleratorText
  1080.  
  1081.     IsTokenValid
  1082.  
  1083.     SGMLGetAttributeData
  1084.  
  1085.     SGMLGetElementData
  1086.  
  1087.     SGMLGetFileRefData
  1088.  
  1089.     Code Example
  1090.  
  1091.  
  1092.  
  1093.  
  1094.