0% found this document useful (0 votes)
5 views23 pages

VBA - Visual Basic Application: 26 March 2025

Uploaded by

dummyforall068
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views23 pages

VBA - Visual Basic Application: 26 March 2025

Uploaded by

dummyforall068
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Classification: Internal

VBA – Visual
Basic Application
26th March 2025

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Overview:
• VBA an event driven programming language form Microsoft that is now predominantly used with Microsoft office applications such as
MS Excel, MS word.
• VBA in Excel as MS-Excel itself provides loads of inbuilt functions.
• VBA allows users to automate tasks and customize functionalities within these applications.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Variables:
• Variable is a named memory location used to hold a value that can be changed during the script execution.
• You must use a letter as the first character.
• You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
• Name can't exceed 255 characters in length.
• You cannot use Visual Basic reserved keywords as variable name.
• Syntax
• In VBA, you need to declare the variables before using them.
Dim <<variable_name>> As <<variable_type>>

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Data Types:
• There are many VBA data types, which can be divided into two main categories, namely numeric and non-numeric data types.
• Numeric Data Types
• Following table displays the numeric data types and the allowed range of values.
Type Range of Values
Byte 0 to 255
Integer -32,768 to 32,767
Long -2,147,483,648 to 2,147,483,648
-3.402823E+38 to -1.401298E-45 for negative values
Single 1.401298E-45 to 3.402823E+38 for positive values.
-1.79769313486232e+308 to -4.94065645841247E-324 for negative values
Double 4.94065645841247E-324 to 1.79769313486232e+308 for positive values.
Currency -922,337,203,685,477.5808 to 922,337,203,685,477.5807
+/- 79,228,162,514,264,337,593,543,950,335 if no decimal is use
Decimal +/- 7.9228162514264337593543950335 (28 decimal places).

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

• Non-Numeric Data Types


• Following table displays the non-numeric data types and the allowed range of values.
Type Range of Values
String (fixed length) 1 to 65,400 characters
String (variable length) 0 to 2 billion characters
Date January 1, 100 to December 31, 9999
Boolean True or False
Object Any embedded object
Variant (numeric) Any value as large as double
Variant (text) Same as variable-length string

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Constant :
• Constant is a named memory location used to hold a value that CANNOT be changed during the script execution. If a user tries to
change a Constant value, the script execution ends up with an error. Constants are declared the same way the variables are declared.
• Following are the rules for naming a constant.
• You must use a letter as the first character.
• You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
• Name can't exceed 255 characters in length.
• You cannot use Visual Basic reserved keywords as variable name.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Operator:
• An Operator can be defined using a simple expression - 4 + 5 is equal to 9. Here, 4 and 5 are called operands and + is called operator.
VBA supports following types of operators −
• Arithmetic Operators
• Comparison Operators
• Logical (or Relational) Operators
• Concatenation Operators
• Arithmetic Operators :
Operator Description Example

+ Adds the two operands A + B will give 15

- Subtracts the second operand from the first A - B will give -5

* Multiplies both the operands A * B will give 50

/ Divides the numerator by the denominator B / A will give 2


Modulus operator and the remainder after an integer
% B% A will give 0
division
^ Exponentiation operator B ^ A will give 100000

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

• Comparison Operators:

Operator Description Example


Checks if the value of the two operands are equal or not. If yes, then the
= (A = B) is False.
condition is true.
Checks if the value of the two operands are equal or not. If the values are not
<> (A <> B) is True.
equal, then the condition is true.
Checks if the value of the left operand is greater than the value of the right
> (A > B) is False.
operand. If yes, then the condition is true.
Checks if the value of the left operand is less than the value of the right
< (A < B) is True.
operand. If yes, then the condition is true.
Checks if the value of the left operand is greater than or equal to the value of
>= (A >= B) is False.
the right operand. If yes, then the condition is true.
Checks if the value of the left operand is less than or equal to the value of the
<= (A <= B) is True.
right operand. If yes, then the condition is true.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

• Logical Operators:
Operator Description Example
Called Logical AND operator. If both the conditions are True, then the
AND a<>0 AND b<>0 is False.
Expression is true.
Called Logical OR Operator. If any of the two conditions are True, then
OR a<>0 OR b<>0 is true.
the condition is true.
Called Logical NOT Operator. Used to reverse the logical state of its
NOT(a<>0 OR b<>0) is
NOT operand. If a condition is true, then Logical NOT operator will make
false.
false.
Called Logical Exclusion. It is the combination of NOT and OR
XOR Operator. If one, and only one, of the expressions evaluates to be (a<>0 XOR b<>0) is true.
True, the result is True.

• Concatenation Operators:
Operator Description Example

+ Adds two Values as Variable. Values are Numeric A + B will give 15

& Concatenates two Values A & B will give 510

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Conditions :

Sr. No. Statement & Description


1 if statement An if statement consists of a Boolean expression followed by one or more statements.
if..else statement An if else statement consists of a Boolean expression followed by one or more statements. If the condition is True, the
2
statements under If statements are executed. If the condition is false, the Else part of the script is executed.
if...elseif..else statement An if statement followed by one or more ElseIf statements, that consists of Boolean expressions and then followed by
3
an optional else statement, which executes when all the condition become false.
4 nested if statements An if or elseif statement inside another if or elseif statement(s).

5 switch statement A switch statement allows a variable to be tested for equality against a list of values.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

LOOP :
• execution flow :

Sr.No. Loop Type & Description

1 for loop Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

2 for ..each loop This is executed if there is at least one element in the group and reiterated for each element in a group.

3 while..wend loop This tests the condition before executing the loop body.

do..while loops The do..While statements will be executed as long as the condition is True.(i.e.,) The Loop should be
4
repeated till the condition is False.
do..until loops The do..Until statements will be executed as long as the condition is False.(i.e.,) The Loop should be
5
repeated till the condition is True.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

String Functions :
• There are predefined VBA String functions, which help the developers to work with the strings very effectively. Following are String methods that are
supported in VBA. Please click on each one of the methods to know in detail.
Sr.No. Function Name & Description
1 InStr Returns the first occurrence of the specified substring. Search happens from the left to the right.
2 InstrRev Returns the first occurrence of the specified substring. Search happens from the right to the left.
3 Lcase Returns the lower case of the specified string.
4 Ucase Returns the upper case of the specified string.
5 Left Returns a specific number of characters from the left side of the string.
6 Right Returns a specific number of characters from the right side of the string.
7 Mid Returns a specific number of characters from a string based on the specified parameters.
8 Ltrim Returns a string after removing the spaces on the left side of the specified string.
9 Rtrim Returns a string after removing the spaces on the right side of the specified string.
10 Trim Returns a string value after removing both the leading and the trailing blank spaces.
11 Len Returns the length of the given string.
12 Replace Returns a string after replacing a string with another string.
13 Space Fills a string with the specified number of spaces.
14 StrComp Returns an integer value after comparing the two specified strings.
15 String Returns a string with a specified character for specified number of times.
16 StrReverse Returns a string after reversing the sequence of the characters of the given string.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Array Functions :
• There are various inbuilt functions within VBScript which help the developers to handle arrays effectively. All the methods that are used in conjunction with
arrays are listed below. Please click on the method name to know about it in detail.

Sr.No. Function & Description

Lbound A Function, which returns an integer that corresponds to the smallest subscript of the given
1
arrays.
Ubound A Function, which returns an integer that corresponds to the largest subscript of the given
2
arrays.
Split A Function, which returns an array that contains a specified number of values. Split based on a
3
delimiter.
Join A Function, which returns a string that contains a specified number of substrings in an array. This is
4
an exact opposite function of Split Method.
Filter A Function, which returns a zero based array that contains a subset of a string array based on a
5
specific filter criteria.
IsArray A Function, which returns a boolean value that indicates whether or not the input variable is an
6
array.

7 Erase A Function, which recovers the allocated memory for the array variables.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

About Macros:
• A macro is a series of functions written in a scripting language that is grouped in a single command to perform the requested task
automatically.
• You can create a macro by editing a file to insert the required functions or you can edit an existing macro to best fit the needs.
• In 3DEXPERIENCE, user can access the Macros Command from the Tools section in the action bar or by using the keyboard keys Alt + F8

• You can Run, Edit, Create, Rename, or Delete the listed macros using the respective options on the Macros dialog box as shown below

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

• In V5, it was possible to locally save the macro code. However, owing to the 3DEXPERIENCE Architecture this possibility does not exist. The
macros are saved in the libraries stored on the PLM Database.

• It is also possible to store CATScript and VBScripts in documents. Basically, macros are stored as objects:
• In a macro library, the macro will be stored in a directory or a VBA project if it exists.
• In a document, the macro will be stored in the current document.
• The following table summarizes where each macro type can be stored

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Types of Libraries :
• A macro library is simply a collection of macros.
• It can be considered as a folder where in all the macros are stored.
• The Macro Libraries dialog box enables users to select the required Library using the Macro Libraries

• In 3DEXPERIENCE, there are three types of Libraries available for selection. The below sections covers each of these libraries.
• PLM Directories:
• The PLM Directories library type allows users to create a macro of the type CAT Script or MS VBScript (VBS)
• CAT Script explicitly requires an object type declaration whereas MS VBScript does not.

MS VBScript : The VBScript language is a subset of the Microsoft Visual Basic Programming language (VBA). The file extension of such script is .cat vbs. All elements
of VBScript are present in VBA, but some VBA elements are not implemented in VBScript. Using the VBScript, you can edit your cat vbs file with a basic text editor such
as Notepad. However, the limitation with VBScript is that it is limited for interface development, and has least functionality as compared to VBA.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

• CAT Script: The CAT Script language is Dassault Systems’ version of VBScript and is very similar to it.
• The file extension of such script macro is .CAT Script.
• VB Scripts and CATScripts can be edited using the Macros Editor as shown below

• PLM VBA projects:


• The PLM VBA Project Library type allows users to create a macro with MS VBA (Visual Basic for Applications)language. VBA provides a
macro editor along with an integrated development environment (IDE) and Object Browser.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Advantages & Disadvantages:


• The main advantages of programing with VBA are:
• User can use a user interface that facilitates editing the macro code.
• Possibility to building forms
• The debugging ability of the macro editor (VBA contains a debugger).
• .
• The disadvantage of programing with VBA are:
• VBA programs cannot be compiled into executables or DLLs.
• VBA scripts may suffer from performance issues when handling large datasets or performing complex calculations.
Compared to compiled languages, VBA scripts may run slower and consume more system resources.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Object Model Map:


• To describe objects, their properties and methods, and the relationships between objects, we use object diagrams and object descriptions.
• Object diagrams describe the overall structure and how objects are linked together.

• Objects are depicted using a blue background color, collections objects in yellow , and abstract objects in purple color
• .

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

About Inheritance, Aggregation, and Object Model:


• Inheritance and aggregation are the two main kinds of relationships between objects.
• Inheritance is the ability of an object to be a specialization of another object. An object that inherits from another object, named the base
object, inherits the properties and the methods of this base object and adds them to its own properties and methods.
• Inheritance helps to specialize objects while gathering common properties and methods in the base object.
• Inheritance is depicted using the following symbol in the object diagrams.

• Aggregation is the ability of an object to contain another one.

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

About Subs and Functions:


• VB can call methods which are exposed by objects. This is facilitated by Subs and Functions.
• Sub:
• If it does not return any value, it is a Sub.
• To pass arguments to a Sub with Visual Basic Script, do not use parentheses Object. Sub arg1, arg2, arg3.
• Function:
• If a value is returned it is a Function.
• Parentheses must be used with a Function.
Dim ReturnedObject As AnyObject
Set ReturnedObject = Object.Function (arg1, arg2)

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

Part Object Model Map :

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.
Classification: Internal

ASIA PACIFIC
25 Rajiv Gandhi Infotech Park /TataTechnologies
Hinjawadi, Pune
@tatatechnologies
India
411057 /TataTech_News
Tel: +91 20 6652 /TataTechnologies
9090 /TataTechnologies
EUROPE
The European Innovation
and Development Centre (EIDC)
tatatechnologie
Olympus Avenue
s.com
Tachbrook Park
Warwick, UK
CV34 6RJ
Tel: +44 (0) 8443 759 685

NORTH AMERICA
6001 Cass Avenue
Suite 600
Detroit MI
USA 48202
Tel: +1 248 426 1482

© Copyright 2023 Tata Technologies. All rights reserved. All other trademarks are trademarks of their respective owners.

You might also like