Using the PerfectScript class to change WordPerfect documents

The PerfectScript class lets you automate specific and repetitive tasks. The members of the PerfectScript class are the product commands that are used in conjunction with the PerfectScript language.


To create a VBA macro that uses the PerfectScript class

WordPerfect Office btnbacktotopproc Using the PerfectScript class to change WordPerfect documents

WordPerfect Office note Using the PerfectScript class to change WordPerfect documents

 
The images that are referenced in this procedure are examples. You can substitute the example images with images of your choice.
1.
 
Click Tools WordPerfect Office onestep Using the PerfectScript class to change WordPerfect documents Visual Basic WordPerfect Office onestep Using the PerfectScript class to change WordPerfect documents Visual Basic Editor.
2.
 
Double-click Project(Document1), and double-click the WordPerfect objects folder in the Project view.
3.
 
Double-click ThisDocument, and type the following lines of code in the Editor window:
Public Sub AddWatermark()
UserForm1.Show
End Sub
This code will add a new method, called AddWatermark, to the ThisDocument class. Userform1 is the name of the form object. The Show method will call Userform1.
4.
 
Click Insert WordPerfect Office onestep Using the PerfectScript class to change WordPerfect documents User form, and change the form so that it resembles the following diagram:

WordPerfect Office vba3 Using the PerfectScript class to change WordPerfect documents

The default names of the controls are used. Located on this form are a CommandButton and a ComboBox. 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.

5.
 
Double-click on the form to access the Editor window, choose General from the Object list box, and add the following code in the Editor window:
Dim myStyle As String
This code will create a string variable called myStyle.
6.
 
Choose Userform from the Object list box.
7.
 
Choose Initialize from the Procedure list box, and add the following code in the UserForm_Initialize method:
Private Sub UserForm_Initialize()
ComboBox1.AddItem “Rose”
ComboBox1.AddItem “World”
ComboBox1.AddItem “Ribbon”
End Sub
This code responds to the event that occurs when the form is initialized. This code adds three string items to the ComboBox1 control.
8.
 
Double-click the CommandButton1 control to create a new method for the UserForm1 class, and type the following lines of code in the CommandButton1_Click method:
Private Sub CommandButton1_
Click()
myStyle = ComboBox1
If myStyle = “” Then
MsgBox “You have not selected a style”, vbExclamation
End If
‘The user selected the rose watermark
If myStyle = “Rose” Then
PerfectScript.ClearDoc
PerfectScript.WatermarkA Create_WatermarkA_Action, OddPages_WatermarkA_Occurrence
PerfectScript.BoxCreate 6
PerfectScript.BoxContentType Image_BoxContentType_Content
PerfectScript.BoxImageRetrieve MakeInternal_BoxImageRetrieve_Action, “C:\rose2.wpg”
PerfectScript.ChangeWatermarkGraphicShade 25
PerfectScript.BoxUpdateDisplay
PerfectScript.BoxEnd Save_BoxEnd_State
PerfectScript.Close
End If
'The user selected the world watermark
If myStyle = “World” Then
PerfectScript.ClearDoc
PerfectScript.WatermarkA Create_WatermarkA_Action, OddPages_WatermarkA_Occurrence
PerfectScript.BoxCreate 6
PerfectScript.BoxContentType Image_BoxContentType_Content
PerfectScript.BoxImageRetrieve MakeInternal_BoxImageRetrieve_Action, “C:\World3.wpg”
PerfectScript.ChangeWatermarkGraphicShade 25
PerfectScript.BoxUpdateDisplay
PerfectScript.BoxEnd Save_BoxEnd_State
PerfectScript.Close
End If
'The user selected the ribbon watermark
If myStyle = “Ribbon” Then
PerfectScript.ClearDoc
PerfectScript.WatermarkA Create_WatermarkA_Action, OddPages_WatermarkA_Occurrence
PerfectScript.BoxCreate 6
PerfectScript.BoxContentType Image_BoxContentType_Content
PerfectScript.BoxImageRetrieve MakeInternal_BoxImageRetrieve_Action, “C:\ribb0002.wpg”
PerfectScript.ChangeWatermarkGraphicShade 25
PerfectScript.BoxUpdateDisplay
PerfectScript.BoxEnd Save_BoxEnd_State
PerfectScript.Close
End If
PerfectScript.ZoomToFullPage
Unload Me
End Sub
This code responds to the event that occurs when you click the command button. Be sure to enter the correct path to where the graphics files are located.

WordPerfect Office note Using the PerfectScript class to change WordPerfect documents

 
In this procedure, a new method called AddWatermark is added to the ThisDocument class. This macro calls a form that lets you select a choice of three watermarks to insert into the odd pages of the document. PerfectScript class members can be accessed only by calling the PerfectScript object, which must be followed by a “.”. You can call the AboutDlg method, which is a PerfectScript class member, by typing PerfectScript.AboutDlg.

Using the PerfectScript class to change WordPerfect documents