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

  1. Global Macros
  2.  
  3. Global macros can be executed in all Corel Presentations documents. Global macros are stored in a special file called Presentations11.GMS. All objects that are used by a Global macro are also stored in the Presentations11.GMS. For example, if a macro uses a form, then the form is stored in the Presentations11.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 Presentations Objects folder that appears under the Global Macros project in the Project view.
  44.  
  45. 8.    Double-click ThisSlideShow that appears under the Global Macros project, 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 ThisSlideShow class. If you declare ShowForm as a Private method, you will not be able to run it from Corel Presentations.
  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 Presentations11.GMS.
  64.   
  65.  
  66.  
  67. Corel Presentations VBA Events
  68.  
  69. Visual Basic for Applications (VBA) 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.
  70.  
  71. Corel Presentations slideshow events can be broken down into two categories: Global and Project events. A Global event is an event which is recognized by all Corel Presentations slide shows. Suppose you create a VBA macro in the AfterOpen Event. This macro would be valid for any Corel Presentations slideshow. In contrast to Global events there are Project events. A Project event is recognized only by the local slideshow.
  72.  
  73. All events in Corel Presentations are code placeholders. It is up to you to code the response. All events are called in response to a specific action. When an action occurs, the appropriate event will be called and 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. All Global events are members of the GlobalMacros class. The name of the object is the same as the class. All Project events are members of the Document class. The name of the object is the same as the class.
  76.  
  77. Global Events
  78.  
  79.     BeforeSwitchDocument()
  80.  
  81.     AfterSwitchDocument()
  82.  
  83.     BeforeNew()
  84.  
  85.     AfterNew()
  86.  
  87.     BeforeOpen()
  88.  
  89.     AfterOpen()
  90.  
  91.     BeforePrint()
  92.  
  93.     AfterPrint()
  94.  
  95.     BeforeClose()
  96.  
  97.     BeforeSave()
  98.  
  99.     AfterSave()
  100.  
  101.     AfterStartup()
  102.  
  103.  
  104.  
  105. Document Events
  106.  
  107.     BeforeOpen()
  108.  
  109.     AfterOpen()
  110.  
  111.     BeforePrint()
  112.  
  113.     AfterPrint()
  114.  
  115.     BeforeSave()
  116.  
  117.     AfterSave()
  118.  
  119.  
  120.  
  121. GlobalMacros.BeforeClose()
  122.  
  123. Syntax
  124.  
  125. Private Sub GlobalMacros_BeforeClose()
  126.  
  127. Description
  128.  
  129. This event is called before you close the slideshow. 
  130.  
  131. Example
  132.  
  133. In the following code fragment, a MessageBox informs the user that the slideshow will be closed.
  134.  
  135. Private Sub GlobalMacros_BeforeClose()
  136.  
  137.  
  138.  
  139. '******* Declare all variables
  140.  
  141. Dim Msg as String 
  142.  
  143. Msg = "You are about to close Presentations?" ' Define message.
  144.  
  145.  
  146.  
  147. '****** Display the MessageBox
  148.  
  149. MsgBox Msg
  150.  
  151. End Sub
  152.  
  153. GlobalMacros.BeforeSwitchDocument()
  154.  
  155. Syntax
  156.  
  157. Private Sub GlobalMacros_BeforeSwitchDocument()
  158.  
  159. Description
  160.  
  161. This event is called when you switch slideshows. The code is executed before the new slideshow appears.
  162.  
  163. Example
  164.  
  165. 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.
  166.  
  167. Private Sub GlobalMacros_BeforeSwitchDocument()
  168.  
  169. '*** Declare all variables
  170.  
  171. Dim myTime
  172.  
  173. Dim myDate As Date
  174.  
  175. Dim myStrTime, myStrDate, Msg As String
  176.  
  177.  
  178.  
  179. '**** Populate the variables
  180.  
  181. myTime = Time
  182.  
  183. myDate = Date
  184.  
  185.  
  186.  
  187. myStrDate = Str(myDate)
  188.  
  189. myStrTime = Str(myTime)
  190.  
  191.  
  192.  
  193. '*** Display the MessageBox
  194.  
  195. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  196.  
  197. MsgBox Msg
  198.  
  199. End Sub
  200.  
  201.  
  202.  
  203. GlobalMacros.AfterSwitchDocument()
  204.  
  205. Syntax
  206.  
  207. Private Sub GlobalMacros_AfterSwitchDocument()
  208.  
  209. Description
  210.  
  211. This event is called after you have switched to a new slideshow. In contrast to BeforeSwitchDocument(), this event is executed after the new slideshow appears.
  212.  
  213. Example
  214.  
  215. 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.
  216.  
  217. Private Sub GlobalMacros_AfterSwitchDocument()
  218.  
  219. '*** Declare all variables
  220.  
  221. Dim myTime
  222.  
  223. Dim myDate As Date
  224.  
  225. Dim myStrTime, myStrDate, Msg As String
  226.  
  227.  
  228.  
  229. '**** Populate the variables
  230.  
  231. myTime = Time
  232.  
  233. myDate = Date
  234.  
  235.  
  236.  
  237. myStrDate = Str(myDate)
  238.  
  239. myStrTime = Str(myTime)
  240.  
  241.  
  242.  
  243. '*** Display the MessageBox
  244.  
  245. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  246.  
  247. MsgBox Msg
  248.  
  249. End Sub
  250.  
  251.  
  252.  
  253. GlobalMacros.BeforeNew()
  254.  
  255. Description
  256.  
  257. This event is called when you select a new slideshow; however, this code is executed before the new slideshow appears.
  258.  
  259. Example
  260.  
  261. In the following example, a form which displays an image appears. The important concept to note is that the form will be appear before the new slideshow appears.
  262.  
  263. Private Sub GlobalMacros_BeforeNew()
  264.  
  265.   FallsForm.Show
  266.  
  267. End Sub
  268.  
  269. GlobalMacros.AfterNew()
  270.  
  271. Syntax
  272.  
  273. Private Sub GlobalMacros_AfterNew()
  274.  
  275. Description
  276.  
  277. This event is called when you select a new slideshow; however, this code is executed after the new slideshow appears.
  278.  
  279. Example
  280.  
  281. In the following example, a textbox is inserted into the first slide.
  282.  
  283. Private Sub Document_AfterOpen()
  284.  
  285.   With PerfectScript
  286.  
  287.     .AddTextBox 3000,3000,10000,4000
  288.  
  289.     .KeyType "Added by AfterOpen event"
  290.  
  291.     .TextEditExit
  292.  
  293.   End With
  294.  
  295. End Sub
  296.  
  297. GlobalMacros.BeforeOpen()
  298.  
  299. Syntax
  300.  
  301. Private Sub GlobalMacros_BeforeOpen()
  302.  
  303. Description
  304.  
  305. This event is called when you open an existing slideshow; however, this code is executed before the slideshow appears.
  306.  
  307. Example
  308.  
  309. In the following code fragment, a form is called which displays the time at which the slideshow is opened.
  310.  
  311. Private Sub GlobalMacros_BeforeOpen()
  312.  
  313.   TimeForm.Show
  314.  
  315. End Sub
  316.  
  317. GlobalMacros.AfterOpen()
  318.  
  319. Syntax
  320.  
  321. Private Sub GlobalMacros_AfterOpen()
  322.  
  323. Description
  324.  
  325. This event is called when you open an existing slideshow. This code is executed after the slideshow has been loaded internally.
  326.  
  327. Example
  328.  
  329. In the following example, a textbox is inserted into the first slide.
  330.  
  331. Private Sub GlobalMacros_AfterOpen()
  332.  
  333.   With PerfectScript
  334.  
  335.     .AddTextBox 3000,3000,10000,4000
  336.  
  337.     .KeyType "Added by AfterOpen event"
  338.  
  339.     .TextEditExit
  340.  
  341.   End With
  342.  
  343. End Sub
  344.  
  345.  
  346.  
  347. GlobalMacros.BeforePrint()
  348.  
  349. Syntax
  350.  
  351. Private Sub GlobalMacros_BeforePrint()
  352.  
  353. Description
  354.  
  355. This event is called when you print the slideshow. The code is executed after the "Print to" dialog box is closed, but before the slideshow is sent to the printer.
  356.  
  357. GlobalMacros.AfterPrint()
  358.  
  359. Syntax
  360.  
  361. Private Sub GlobalMacros_AfterPrint()
  362.  
  363. Description
  364.  
  365. This event is called when you print the slideshow. The code is executed after the slideshow is sent to the printer.
  366.  
  367. GlobalMacros.BeforeSave()
  368.  
  369. Syntax
  370.  
  371. Private Sub GlobalMacros_BeforeSave()
  372.  
  373. Description
  374.  
  375. This event is called when you save the slideshow. This code is executed just before the slideshow is saved allowing you to customize your slideshow.
  376.  
  377. GlobalMacros.AfterSave()
  378.  
  379. Syntax
  380.  
  381. Private Sub GlobalMacros_AfterSave()
  382.  
  383. Description
  384.  
  385. This event is called after you have saved your slideshow. 
  386.  
  387. Example
  388.  
  389. 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.
  390.  
  391. Private Sub GlobalMacros_AfterSave()
  392.  
  393. '*** Declare all variables
  394.  
  395. Dim myTime
  396.  
  397. Dim myDate As Date
  398.  
  399. Dim myStrTime, myStrDate, Msg As String
  400.  
  401.  
  402.  
  403. '**** Populate the variables
  404.  
  405. myTime = Time
  406.  
  407. myDate = Date
  408.  
  409.  
  410.  
  411. myStrDate = Str(myDate)
  412.  
  413. myStrTime = Str(myTime)
  414.  
  415.  
  416.  
  417. '*** Display the MessageBox
  418.  
  419. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  420.  
  421. MsgBox Msg
  422.  
  423. End Sub
  424.  
  425. GlobalMacros.AfterStartup()
  426.  
  427. Syntax
  428.  
  429. Private Sub GlobalMacros_AfterStartup()
  430.  
  431. Description
  432.  
  433. This event is called when Corel Presentations starts. The code in this event is executed while the splash screen is active.
  434.  
  435. Example
  436.  
  437. In the following code fragment, a MessageBox appears asking the user if they want a textbox inserted into the new slide. If the user selects Yes, then the textbox will be inserted into the slide.
  438.  
  439. Private Sub GlobalMacros_AfterStartup()()
  440.  
  441.  
  442.  
  443. '******* Declare all variables
  444.  
  445. Dim Msg, Style, Title, Response
  446.  
  447.  
  448.  
  449. Msg = "Do you want to insert a text box?" ' Define message.
  450.  
  451. Style = vbYesNo + vbQuestion ' Define buttons.
  452.  
  453. Title = "Presentations 11.0" ' Define title.
  454.  
  455.  
  456.  
  457. '****** Get the Users Input
  458.  
  459. Response = MsgBox(Msg, Style, Title)
  460.  
  461.  
  462.  
  463. If Response = vbYes Then ' User chose Yes.
  464.  
  465. '****** Insert a chart    
  466.  
  467. With PerfectScript
  468.  
  469. .AddTextBox 3000,3000,10000,4000
  470.  
  471. .KeyType "Added by AfterStartup event"
  472.  
  473. .TextEditExit
  474.  
  475. End With
  476.  
  477. Else
  478.  
  479.  MsgBox ("No text box was inserted!")
  480.  
  481. End If
  482.  
  483. End Sub
  484.  
  485.  
  486.  
  487. Document.BeforeOpen()
  488.  
  489. Syntax
  490.  
  491. Private Sub Document_BeforeOpen()
  492.  
  493. Description
  494.  
  495. This event is called when you open a slideshow. The code in the event is executed before the slideshow appears.
  496.  
  497. Example
  498.  
  499. In the following code fragment, a Message Box appears which displays the time and date. This data can be written to a database that keeps track of file activities.
  500.  
  501. Private Sub Document_BeforeOpen()
  502.  
  503. '*** Declare all variables
  504.  
  505. Dim myTime
  506.  
  507. Dim myDate As Date
  508.  
  509. Dim myStrTime, myStrDate, Msg As String
  510.  
  511.  
  512.  
  513. '**** Populate the variables
  514.  
  515. myTime = Time
  516.  
  517. myDate = Date
  518.  
  519.  
  520.  
  521. myStrDate = Str(myDate)
  522.  
  523. myStrTime = Str(myTime)
  524.  
  525.  
  526.  
  527. '*** Display the Message Box
  528.  
  529. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  530.  
  531. MsgBox Msg
  532.  
  533. End Sub
  534.  
  535. Note
  536.  
  537.   The Message Box will appear before the slideshow is opened. After the Message Box is closed, the slideshow will open. 
  538.   
  539.  
  540.  
  541. Document.AfterOpen()
  542.  
  543. Syntax
  544.  
  545. Private Sub Document_AfterOpen()
  546.  
  547. Description
  548.  
  549. This code is executed after the slideshow has been loaded internally. You can customize your slideshow by writing code in this event.
  550.  
  551. Example
  552.  
  553. In the following example, a textbox is inserted into the first slide.
  554.  
  555. Private Sub Document_AfterOpen()
  556.  
  557.   With PerfectScript
  558.  
  559.     .AddTextBox 3000,3000,10000,4000
  560.  
  561.     .KeyType "Added by AfterOpen event"
  562.  
  563.     .TextEditExit
  564.  
  565.   End With
  566.  
  567. End Sub
  568.  
  569.  
  570.  
  571. Document.AfterPrint()
  572.  
  573. Syntax
  574.  
  575. Private Sub Document_AfterPrint()
  576.  
  577. Description
  578.  
  579. This event is called after you have printed your slideshow.
  580.  
  581. Example
  582.  
  583. You can create a simple macro that informs the user that the slideshow is printed by coding a Message Box.
  584.  
  585. Private Sub Document_AfterPrint()
  586.  
  587.   MsgBox ("You have just printed this slideshow")
  588.  
  589. End Sub
  590.  
  591. Document.BeforePrint()
  592.  
  593. Syntax
  594.  
  595. Private Sub Document_BeforePrint()
  596.  
  597. Description
  598.  
  599. This event is called just before the slideshow is sent to the printer. This enables you to customize your slideshow before it is printed.
  600.  
  601. Example
  602.  
  603. In the following example, a form is called which simply displays an image.
  604.  
  605. Private Sub Document_BeforePrint()
  606.  
  607. '******* Call the Form
  608.  
  609.   FallsForm.Show
  610.  
  611. End Sub
  612.  
  613.  
  614.  
  615. Note
  616.  
  617.   The FallsForm is a VB Form which contains an image control.
  618.   
  619.  
  620.  
  621. Document.AfterSave()
  622.  
  623. Syntax
  624.  
  625. Private Sub Document_AfterSave()
  626.  
  627. Description
  628.  
  629. This event is called after you have saved your slideshow.
  630.  
  631. Example
  632.  
  633. 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.
  634.  
  635. Private Sub Document_AfterSave()
  636.  
  637. '*** Declare all variables
  638.  
  639. Dim myTime
  640.  
  641. Dim myDate As Date
  642.  
  643. Dim myStrTime, myStrDate, Msg As String
  644.  
  645.  
  646.  
  647. '**** Populate the variables
  648.  
  649. myTime = Time
  650.  
  651. myDate = Date
  652.  
  653.  
  654.  
  655. myStrDate = Str(myDate)
  656.  
  657. myStrTime = Str(myTime)
  658.  
  659.  
  660.  
  661. '*** Display the Message Box
  662.  
  663. Msg = "The date is " & myStrDate & " and the time is " & myStrTime
  664.  
  665. MsgBox Msg
  666.  
  667. End Sub
  668.  
  669.  
  670.  
  671. Document.BeforeSave()
  672.  
  673. Syntax
  674.  
  675. Private Sub Document_BeforeSave()
  676.  
  677. Description
  678.  
  679. This event is called just before the slideshow is saved. This gives you a chance to customize your slideshow before it is saved.
  680.  
  681. Example
  682.  
  683. In the following example, the zoom setting is changed so that all objects in the slide are playback size. This setting will last until it is changed.
  684.  
  685. Private Sub Document_BeforeSave()
  686.  
  687.   PerfectScript.ZoomToSlideShowSize
  688.  
  689. End Sub
  690.  
  691. Document.BeforeClose()
  692.  
  693. Syntax
  694.  
  695. Private Sub Document_BeforeClose()
  696.  
  697. Description
  698.  
  699. This event is called when the slideshow is closed; however, this code is executed before the slideshow is actually closed.
  700.  
  701. Example
  702.  
  703. In the following code example, a Message Box will inform the user that the slideshow will close. This Message Box will appear before the slideshow is closed.
  704.  
  705. Private Sub Document_BeforeClose()
  706.  
  707.   MsgBox "You are about to close this slideshow"
  708.  
  709. End Sub
  710.  
  711. Working with product commands that use a variable
  712.  
  713. You must declare a variable that you pass to a product command as a Variant.
  714.  
  715. Refer to the following code fragment:
  716.  
  717.  
  718.  
  719. '**** Declare the variable
  720.  
  721. Dim myAnswer As Variant
  722.  
  723.  
  724.  
  725. '*** Pass the variable to DirectoryExists()
  726.  
  727. PerfectScript.DirectoryExists myAnswer, "D:\Client"
  728.  
  729. MsgBox myAnswer
  730.  
  731. Code Explanation
  732.  
  733. 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. 
  734.  
  735.  
  736.  
  737. Corel Presentation product commands that use WordPerfect unit values
  738.  
  739. There are many product commands which require an argument to be expressed in WordPerfect units. Here is a formula to help convert from inches to WordPerfect units:
  740.  
  741. WordPerfect unit = (n*1200), where n is inches.
  742.  
  743. Product commands that use unit values:
  744.  
  745.     AddArc
  746.  
  747.     AddPolyCurve
  748.  
  749.     AddPolyLine
  750.  
  751.     AddPolyLineWithEndCaps
  752.  
  753.     AddRoundedRect
  754.  
  755.     AddTextBox
  756.  
  757.     ChartSetCreateSize
  758.  
  759.     DocumentFormSettings
  760.  
  761.     DrawingSizeSettings
  762.  
  763.     ObjectAreaSelect
  764.  
  765.     ObjectMove
  766.  
  767.     ObjectPointSelect
  768.  
  769.     ObjectScale
  770.  
  771.     ObjectSetLineWidth
  772.  
  773.     PreferenceFormSettings
  774.  
  775.     PrintDocument
  776.  
  777.     SetGridSnapOptions
  778.  
  779.     SetTextLineAttributes
  780.  
  781.     TextKerning
  782.  
  783.  
  784.  
  785. Working with repeating parameters
  786.  
  787. You must create and pass an array to each product command that has repeating parameters. Refer to the following code example, which illustrates two different code techniques:
  788.  
  789. Example 1
  790.  
  791. Sub TestPolyLine()
  792.  
  793.   Dim x As Variant
  794.  
  795.   Dim y As Variant
  796.  
  797.   x = Array (3000,8000,8000,3000)
  798.  
  799.   y = Array (3500,3200,7500,7000)
  800.  
  801.   With PerfectScript
  802.  
  803.     .AddPolyLine OpenFrame_AddPolyLine_FillAndFrame, 4, x, y
  804.  
  805.   End With
  806.  
  807. End Sub
  808.  
  809. Example 2
  810.  
  811. Sub TestSelectBox()
  812.  
  813.   Dim box As Variant
  814.  
  815.   box = Array (1,2,2,0)
  816.  
  817.   With PerfectScript
  818.  
  819.     .ChartCreateOrg Button1_ChartCreateOrg_GalleryStyle
  820.  
  821.     .SelectBox On_SelectBox_Select, box
  822.  
  823.   End With
  824.  
  825. End Sub
  826.  
  827. Note
  828.  
  829.   You must use the integer values when populating an array used for repeating parameters.
  830.   
  831. Product commands with repeating parameters 
  832.  
  833. 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 The following list is all the product commands with repeating parameters:
  834.  
  835. Product commands with repeating parameters:
  836.  
  837.     AddPolyCurve
  838.  
  839.     AddPolyLine
  840.  
  841.     AddPolyLineWithEndCaps
  842.  
  843.     AirBrush
  844.  
  845.     ChartBoxFields
  846.  
  847.     PaintBrush
  848.  
  849.     PaintEraser
  850.  
  851.     SelectBox
  852.  
  853.     SelectiveReplace
  854.  
  855.     Code Example%43211>commands 
  856.  
  857. VBA programming issues relating to product commands
  858.  
  859. 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 gray boxes for a detailed explanation: 
  860.  
  861.  
  862.  
  863.     Product commands with repeating parameters
  864.  
  865.     Calling product commands outside of the intended scope
  866.  
  867.     Product commands that require a unit
  868.  
  869.  
  870.  
  871.  
  872.