How To Create A Program In Excel

Table of contents:

How To Create A Program In Excel
How To Create A Program In Excel

Video: How To Create A Program In Excel

Video: How To Create A Program In Excel
Video: Filipino Tutorials ( Create Data Entry Form Using Excel + VBA Programming 2024, December
Anonim

All applications from the Microsoft Office suite support the ability to embed executable code - scripts - into their documents. With their help, you can solve a wide range of tasks in the automation of data processing. And using forms will literally create a program based on an office application. This can be done, for example, in Excel.

How to create a program in Excel
How to create a program in Excel

Necessary

Microsoft Office Excel

Instructions

Step 1

Start Microsoft Office Excel. Create a new document if necessary. To do this, press the Ctrl + N keys or expand the "File" menu and select the "New …" item. Then click on the "Blank Book" link in the "Book Creation" panel.

Step 2

Open a Visual Basic Editor window. To do this, press Alt + F11 or select Visual Basic Editor from the Macro section of the Tools menu. There you will see a project panel displaying the object tree of the given Excel workbook, as well as the forms, modules, and class modules it contains.

Step 3

Create forms if needed. In the main menu, click on Insert and then UserForm. A new item is added in the Forms section of the project panel. When created, the form will be automatically opened. Use the mouse to drag controls from the Toolbox to the form window. Change their size and position. After selecting with the mouse, change their properties in the Properties panel. Save shapes by pressing Ctrl + S.

Step 4

Create as many modules or class modules as needed. To do this, select the Module or Class Module items in the Insert section of the main menu. Open the code editing windows for the required modules or forms by double-clicking on the corresponding elements in the project window.

Step 5

Add class declarations to class modules. Define them using the Class keyword:

Class CSampleClass

End Class

Step 6

Add methods to class definitions, and function and procedure stubs to modules. Functions are declared using the Function keyword, followed by a name and a set of parameters, separated by commas, enclosed in parentheses. For example:

Function SampleFunction (a, b, c)

End Function

Similarly (only using the Sub keyword) procedures are declared:

Sub SampleProcedure (a, b)

End Sub

Step 7

Declare class members, as well as global and local (in functions and methods) variables. To do this, use the Dim … As clause (the type of the variable is indicated after the As keyword). For example, declaring a variable oWB that stores a reference to a book object might look like this:

Dim oWB As Excel. Workbook

By specifying the dimension in parentheses, you can declare an array:

Dim aWBooks (10) As Excel. Workbook

Step 8

Implement the algorithm of the program by making changes to the code of functions, procedures, class methods. Use Visual Basic control structures to control the flow of execution. Work with your own data structures, built-in form objects and built-in Excel objects.

Recommended: