Professional Documents
Culture Documents
BusinessObjects Enterprise XI R2
Patents Business Objects owns the following U.S. patents, which may cover products that are offered
and sold by Business Objects: 5,555,403, 6,247,008 B1, 6,578,027 B2, 6,490,593 and
6,289,352.
Trademarks Business Objects, the Business Objects logo, Crystal Reports, and Crystal Enterprise are
trademarks or registered trademarks of Business Objects SA or its affiliated companies in the
United States and other countries. All other names mentioned herein may be trademarks of
their respective owners.
Third-party Business Objects products in this release may contain redistributions of software licensed
contributors from third-party contributors. Some of these individual components may also be available
under alternative licenses. A partial listing of third-party contributors that have requested or
permitted acknowledgments, as well as required notices, can be found at:
http://www.businessobjects.com/thirdparty
Contents
Chapter 1 Introduction 7
About this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Who should read this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Business Objects information resources . . . . . . . . . . . . . . . . . . . . . . . . 8
Creating an Add-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Installing an Add-in Using the Interface . . . . . . . . . . . . . . . . . . . . . . . . 22
Desktop Intelligence Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Event Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Notes on the order in which events occur . . . . . . . . . . . . . . . . . . . 23
Implementing an Event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Implementing Application Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Index 55
Introduction
chapter
1 Introduction
About this guide
chapter
2 Getting Started with VBA
Overview
Overview
You can use Microsoft Visual Basic for Applications (VBA) to create custom
macros and add-ins in Desktop Intelligence. Because VBA is also used by
Microsoft Office products and by an increasing number of other Windows
software products, you can integrate and customize applications already
available on the user’s desktop.
Comprehensive on-line help about the VBA development environment and
language is available from the VBA Help menu and when you press F1 in the
VBA development environment.
This chapter provides an overview of how VBA gives you the power to extend
the capabilities of Desktop Intelligence. This chapter also describes how you
can develop macros and add-ins using VBA to control the Desktop
Intelligence and Designer environments, as well as perform queries and
analysis on data in documents through universes and data providers.
The Visual Basic editor is the standard Microsoft VBA editor which is included
with Microsoft Office 2000. So, you can use tools such as Object Browser and
Project Explorer. On-line help for VBA is also available from the editor.
Variables
VBA supports the following data types: Boolean, Byte, Integer, Long, Single,
Double, Currency, Date, Object, String, Variant and user-defined.
You declare variables using the Dim keyword. For example:
Dim Name As String
Procedures
VBA provides two different type of procedures: functions, and sub-routines.
Functions can return values, sub-routines have no return value.
Implementing Events
VBA is event-driven. That is, the model for VBA is that your code is executed
when certain events in the application take place. Examples of events are a
user opening a document, and a user clicking on a button. The code that
executes when an event is triggered is called the implementation of the event.
Note that the Universe Designer SDK does not have any events to
implement. This means that you cannot write code to respond to events in the
Designer application. You can, however, use the Designer object model in the
implementation of the events of other applications.
For more information on implementing events see “Desktop Intelligence
Events” on page 23 and “Creating Your Own Forms” on page 34.
Flow Control
The following list describes the most commonly used VBA flow control
structures.
Control Description
If-Then-Else Tests a condition and alters the execution flow based on the
results of the test
For-Next Carries out a repetitive action a specific number of times
While-Wend Carries out a repetitive action while a condition is true
Do-Loop Carries out a repetitive action either while a condition is true or
until it becomes true
Select-Case Branches to one of several possible code segments based on
the value of a variable or the outcome of a test
For-Each-Next Performs a repetitive action on each object in a collection or on
each item of an array
Arrays
An array is a variable that contains multiple values. Each value is indexed and
all the elements of the array have the same data type.
VBA supports multi-dimensional arrays.
Declaring an array
To declare an array in VBA use the following syntax.
Dim ArrayName(n, m, ..., z) As DataType
n, m, …, z are integers that represent the size of a dimension. In VBA you can
declare an array with up to 60 dimensions.
Example: Declaring a two dimensional array
The following VBA code fragment declares an array with two dimensions. The
size of each dimension is determined by the constant MAX_CUSTOMERS.
Const MAX_CUSTOMERS As Integer = 500
Dim customers(MAX_CUSTOMERS, MAX_CUSTOMERS) As String
Array indexes
By default the first element of an array is element zero and the last is n. You
can change this using Option Base statement.
With Statement
The With statement is a useful tool for abbreviating object references.
Example: Using a With statement in an object reference
The following code fragment sets the properties of an object using the With
statement.
With
Application.ActiveDocument.DataProviders.Item(1).Queries
.DuplicateRows = TRUE
.DeleteTrailingBlanks = TRUE
.ScopeOfAnalysis = boThreeLevelsDown
End With
Error Handling
You can use the statement On Error to handle errors generated during
execution.
If you don't use an On Error statement, any run-time error that occurs is fatal.
That is, an error message is displayed and execution stops.
Example: Handling errors with the On Error statement
Sub Convert(...)
On Error Goto ErrorDisplay
... ’if an error occurs here go to ErrorDisplay
Exit Sub
ErrorDisplay: MsgBox Err.Number & "-" & Err.Description
Sub End
Name Description
Abs Returns the absolute value of a number
CurDir Returns the current MS-DOS path
chapter
3 Programming with Desktop Intelligence
Overview
Overview
This chapter explains how to program with Desktop Intelligence.
It covers the following topics:
• Macros and Sub-routines
• Add-ins
• Desktop Intelligence Events
• Implementing Application Events
Creating a Macro
The procedure for creating a macro is as follows:
1. Select Macro from the Tools menu.
2. On the submenu, select Macros. The Macros dialog box appears:
In the Macros dialog box, you can display the names of add-ins, or the
macros contained in the open document, or a combination of both.
1. Enter a name for the macro and click Create. The VBA environment is
opened and a module containing a skeleton subroutine for your macro is
created.
2. You can now begin writing your macro.
When your macro is complete, and compiles successfully, you should select
Close and Return to Desktop Intelligence from the File menu. You can now
run the macro from the Macros dialog box. If you wish, you can also associate
your macro with a button on the tool bar. This procedure is described in ‚
“Customizing the User Interface”.
Run
selected
macro
Debug selected
macro
List of Edit selected
available macro
macros
Delete
selected macro
Show macros
contained in Add a
selected item description for
the selected
macro
Visual Basic
Editor
• Visual Basic Editor. Click this to open the VBA environment for editing a
procedure or macro.
• Run Associated Macro. Click this button to run a macro associated with
this button.
3. Click the check box beside the number of the button with which you wish
to associate the macro.
Add-ins
Add-ins are programs that give optional commands and features to Desktop
Intelligence. They are saved with the extension .rea.
Before you can use an add-in, you must load it on your computer and then
install it in Desktop Intelligence. Once you install an add-in, it remains there
each time you launch Desktop Intelligence.
To conserve memory, uninstall add-ins you do not use often. Uninstalling an
add-in removes its features and commands from Desktop Intelligence, but the
add-in program remains on your computer so you can easily install it again.
Unlike macros, add-ins are not associated with a single document—once
installed, an add-in will function just like any other feature of the Desktop
Intelligence application.
You can distribute add-ins you have created to other users and retrieve and
use add-ins that others have created.
Creating an Add-in
You can create add-ins in Desktop Intelligence, and distribute them to other
users or save them to BusinessObjects Enterprise.
To create an add-in:
1. Create a new document.
2. Open the VBA editor.
3. Write and compile the add-in.
4. Select Close and Return to Desktop Intelligence from the File menu.
5. From the File menu select Save As...
6. Select Desktop Intelligence Addins (*.rea) from the Save as type list box.
3. Click the check box of the add-in you wish to install. If it is not visible in
the Add-Ins dialog box, you can search for it by clicking the Browse
button.
4. Click OK.
You can run an installed add-in from the Macros dialog box, or you can
associate it with a button on the Visual Basic tool bar. This procedure is
described in ‚ “Customizing the User Interface”.
Event Triggers
Events can be triggered by user actions or by use of methods in the Desktop
Intelligence SDK. For example, a BeforeRefresh event (application and
document) is triggered by the user clicking the Refresh button in the Desktop
Intelligence user interface, or by a call to the Document.Refresh method.
Implementing an Event
Each event that you can implement appears in the VBA procedure list for its
corresponding object.
Object Procedure
Document events
Implementation of the BeforeSave Document event:
Document_BeforeSave()
To implement an event, insert the code that you want to execute when the
event occurs in the procedure corresponding to the event.
This process is the same as the one for implementing form events in the user
interface. See “Creating Your Own Forms” on page 34.
Example: Implementation of the DocumentBeforeRefresh event
The following code could be useful for a document that will take a long time to
refresh.
Private Sub Document_BeforeRefresh(Cancel As Boolean)
Dim Response As Variant'user’s response to the message
1 AppRefClass
Application
Create • boapp As Application 2
class
Set reference
Create 4
3 object
AppRef 5
• boapp Private Sub
boapp_DocumentOpen(
Implement
‘whenever a document is
event opened
MsgBox "Are you
ready?"
End Sub
The Public part of the declaration makes the property globally available. The
WithEvents part of the declaration gives you access to the events defined for
the Application class. For more information on the Public and WithEvents key
words refer to the Visual Basic documentation.
In another module create an instance of AppRefClass called, for example,
AppRef:
Dim AppRef As New AppRefClass
Then, in a sub-routine set AppRef.boapp:
Sub Initialize()
Set AppRef.boapp = Application
...
End Sub
Now, the events of the Application object can be implemented using
AppRef.boapp.
chapter
4 Customizing the User Interface
Overview
Overview
This chapter explains how to customize the User Interface with the Desktop
Intelligence SDK.
It covers the following topics:
• User Interface Classes
• Adding a Command Bar
• Adding Controls to a Command Bar
• Creating Forms.
Application
Clipboard CmdBarControl
CmdBarButton
CmdBarPopup
Command Bars
A command bar can be a tool bar, a menu bar, or a pop-up. Adding tool bars
and pop-up menus to the Desktop Intelligence interface is described in
“Adding a Command Bar” on page 32.
Menu Bar
Sorts
command bar
Charts
(menu bar)
Standard
Visual Basic
command bar (tool bar -
Borders
normal)
Formatting
Report command bar (pop-up)
Structure
Document Exchange
Alignment
Formula Bar
Controls
There are two types of controls: pop-ups and buttons. Pop-ups present lists of
buttons which, when selected, perform actions.
control (pop-up)
control (button)
CmdBar CmdBarControls
CmdBarControl
CmdBarButton
CmdBarPopup
The CmdBarControls collection contains all the controls for a command bar.
CmdBarControl is a generic class that represents a control.
CmdBarButton and CmdBarPopup are special cases of CmdBarControl.
They have the properties and methods of CmdBarControl plus others related
to their specialization.
The items in the CmdBarControls collection are of the type CmdBarControl.
However, if you know what type of control you are accessing, you can use the
specialized properties and methods. Most commonly you need to use this for
nesting controls.
When pop-up controls contain other controls they act as a command bar.
They have their own collection of controls that you can access using
CmdBarPopup.Controls.
CmdBarControls
CmdBarButton
CmdBarButton
CmdBarPopup CmdBarControls
CmdBarButton CmdBarButton
CmdBarPopup CmdBarControls
Once you have added a command bar you need to add controls that users
use to access the functions you are providing. See “Adding Controls to a
Command Bar” on page 32.
Form events
Add pop-up
Click event
Implement
Click event
chapter
5 Data Providers
Overview
Overview
This chapter describes the concepts associated with Data Providers using the
Desktop Intelligence SDK. It describes the different types of data provider and
how to access these sources of data.
More specifically, it describes:
• Working with Existing Data Providers
• Creating a Query Technique Data Provider
• Creating a VBA Procedure Data Provider.
Document DataProviders
DataProvider
Columns Column
Queries
Only data providers that query universes have a Queries object. See “Query
technique” on page 40 for more information on the Queries class.
The columns in the Results tab of the Data Manager dialog box are the same
columns you can access using the Columns class.
Example: Accessing the properties of a data provider
Sub Show_DP_Names()
Dim i As Integer
Dim message As String
For i = 1 To
Application.ActiveDocument.DataProviders.Count
message = message & Chr(10) &
Application.ActiveDocument.DataProviders.Item(i).Name
Next
MsgBox message ’display the names
End Sub
Thi.
Query technique
A query technique is a data provider that queries a universe. When you use
the Desktop Intelligence Query Panel you create a query technique data
provider.
The parts of a query technique data provider are:
• universe
• query(ies)
The universe part defines where the information comes from. For example,
the “eFashion” universe stored in the “General” repository. This corresponds
to choosing the universe in the New Report wizard.
The query part defines which parts of the universe you are interested in. For
example the Year object of the Time period class, and the Sales revenue
object of the Measures class, where Year is equal to 2000.
Queries
Sorts Sort
Query
Conditions Condition
Results Result
VBA procedure
A VBA procedure data provider is a VBA routine that retrieves data from non-
standard sources and constructs a microcube. You can access the parts of a
VBA procedure data provider through the DpVBAInterface class.
See “Creating a VBA Procedure Data Provider” on page 43 for information on
the DpVBAInterface class and how to create a VBA procedure data provider.
Stored procedure
A stored procedure data provider is an SQL script that is saved and executed
in a database.
A stored procedure data provider has no Queries object.
Error handling
If you do not unload a data provider from memory when you have finished
with it, it will slow down your system and may ultimately crash you program.
It is recommended that when you load and unload a data provider to and from
memory you include a call to DataProvider. Unload in an error-handling
mechanism. If an error occurs while the data provider is loaded in memory
you could experience system errors.
Example: Unloading a data provider in an error handler
The following code fragments show how to ensure that a data provider is
removed from memory in the case of an error after it has been loaded.
Sub Modify_DataProvider()
Dim boDP As DataProvider
On Error Goto DPError’if there’s an error handle it
Set boDP =
Application.ActiveDocument.DataProviders.Item(1)
boDP.Load ’load the data provider into memory
... ’do some processing with the data provider
boDP.Unload ’unload the data provider from memory
...
Exit Sub
DPError:
boDP.Unload ’make sure that the data provider is not
in memory
MsgBox "An error occurred..."’display an error message
End Sub
4. Enter the code for your VBA procedure, save your work, and return to
Desktop Intelligence.
The code for a VBA data provider:
• defines the parameters of the DataProvider object and the microcube
that will contain the data
• collects the data and puts it in a microcube column by column
5. Click Run.
Desktop Intelligence executes your procedure and creates two objects: a
DpVBAInterface object and a corresponding DataProvider object. The
type of the DataProvider object is “DPVBAC” to indicate that it is a VBA
procedure data provider.
Example: Filling a microcube
The following example shows how to fill a column in a microcube with data. In
this case the data is simply a number. If you want to add information from
another source, you need to add code to fetch the data.
Sub SimpleDpVBA(dpInterface As DpVBAInterface)
Dim i As Integer'loop index
Dim Col As DpVBAColumn'a column in the microcube
Dim Cols As DpVBAColumns'the columns of the microcube
Dim newCube As DpVBACube'the microcube we’re filling
The data providers you define in this way appear in the list of VBA data
providers when you use the New Report and New Data wizards.
DpVBAInterface
DpVBACubes DpVBACube
DpVBAColumns DpVBAColumn
Run
fill
data source display
appendix
A Documentation and information services
Documentation
You can find answers to your questions on how to install, configure, deploy,
and use Business Objects products from the documentation.
Address Content
Business Objects product Information about the full range of
information Business Objects products.
http://www.businessobjects.com
Product documentation Business Objects product
http://www.businessobjects.com/ documentation, including the
support Business Objects Documentation
Roadmap.
Business Objects Documentation Send us feedback or questions
mailbox about documentation.
documentation@businessobjects.com
Online Customer Support Information on Customer Support
http://www.businessobjects.com/ programs, as well as links to
support/ technical articles, downloads, and
online forums.
Business Objects Consulting Information on how Business
Services Objects can help maximize your
http://www.businessobjects.com/ business intelligence investment.
services/consulting/
Business Objects Education Information on Business Objects
Services training options and modules.
http://www.businessobjects.com/
services/training
XML 43 application 23
data providers 37–47 document 23, 24
editing 46 form 34
freehand SQL 41 implementing 11, 24
handling errors 41 order 23
loading and unloading 41 triggers 23
optimizing 41 Excel
personal text file 41 querying 41
query technique 40 executing macros 19
stored procedure 41 Extended Markup Language
types 39 see XML
VBA procedure see VBA procedure data external object libraries 14
provider
dBASE F
querying 41
faces
declaring
adding 33
arrays in VBA 12
recommended size 34
variables in VBA 11
feedback, on documentation 51
Desktop Intelligence
filling a microcube 43
customizing the interface 27
flow control
development environment
in VBA 12
VBA 10, 14
forms
disabling
creating 34
macros 18
freehand SQL data provider
displaying pop-up menus 32
definition 41
distributing
functions 11, 14
add-ins 21
VBA procedure data provider 47
document events 23, 24 H
documentation handling
feedback on 51 errors in VBA 13
on product CD 50
on the web 50 I
roadmap 50
implementing
DpVBAInterface object 43, 45
form events 34
implementing events 11, 24
E including
editing external object libraries in VBA 14
data provider 46 indexing
education. See training arrays in VBA 12
errors information resources 50
data providers 41 Internet
handling 41 querying 43
handling in VBA 13
events
L procedures 11
loading browsing in VBA 14
data providers 41
Q
M Queries object 43
macros 10 Query Panel 43
adding 20 query technique data provider
creating 18 creating 39, 42
running 19 definition 40
tool tips 20 running and refreshing 43
memory management
data providers 41 R
menu bar .rea 21
definition 29 referencing
menus external object libraries in VBA 14
nesting 31 refreshing
microcube 46 data providers 46
filling 43, 43, 44 query technique data provider 43
reports 43, 46
N creating 45
nesting controls 31 repository 40
resources 50
running
O data providers 46
Object Browser 10 macros 19
opening 14 query technique data provider 43
object models
user interface 28
objects S
browsing in VBA 14 sharing
external 14 VBA procedure data providers 47
On Error statement 13 showing pop-up menus 32
Online Customer Support 51 SQL 43
optimizing data provider 41
data providers 41 stored procedure data provider
definition 41
sub-routines 11, 18
P support
personal text file data provider customer 51
definition 41 locations 51
pop-up menus technical 51
adding 32 web site 51
definition 29, 30
displaying 32
nesting 31
V
VBA 9–??
arrays 12
creating forms 34
data provider see VBA procedure data provider
data types 11
events 11
flow control 12
functions 14
implementing an event 24
language summary 11
On Error statement 13
variables 11
With statement 13
writing macros 18
VBA procedure data provider
creating 39, 43
defining 43
defining with SDK 44
definition 41
development environment 10
distributing 47
DpVBAInterface class 45
executing with SDK 46