Michael Alexander - Excel 2019 Power Programming with VBA

Здесь есть возможность читать онлайн «Michael Alexander - Excel 2019 Power Programming with VBA» — ознакомительный отрывок электронной книги совершенно бесплатно, а после прочтения отрывка купить полную версию. В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: unrecognised, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Excel 2019 Power Programming with VBA: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Excel 2019 Power Programming with VBA»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Maximize your Excel experience with VBA
Excel 2019 Power Programming with VBA Understanding how to leverage VBA to improve your Excel programming skills can enhance the quality of deliverables that you produce—and can help you take your career to the next level.
Explore fully updated content that offers comprehensive coverage through over 900 pages of tips, tricks, and techniques Leverage templates and worksheets that put your new knowledge in action, and reinforce the skills introduced in the text Improve your capabilities regarding Excel programming with VBA, unlocking more of your potential in the office
 is a fundamental resource for intermediate to advanced users who want to polish their skills regarding spreadsheet applications using VBA.

Excel 2019 Power Programming with VBA — читать онлайн ознакомительный отрывок

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Excel 2019 Power Programming with VBA», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

FIGURE 215 The General tab of the Options dialog box The Docking tab Figure - фото 22

FIGURE 2.15 The General tab of the Options dialog box

The Docking tab

Figure 2.16shows the Docking tab. These options determine how the various windows in the VBE behave. When a window is docked, it is fixed in place along one of the edges of the VBE program window. This makes it much easier to identify and locate a particular window. If you turn off all docking, you have a big, confusing mess of windows. Generally, the default settings work fine.

FIGURE 216 The Docking tab of the Options dialog box VBA Fundamentals VBA is - фото 23

FIGURE 2.16 The Docking tab of the Options dialog box

VBA Fundamentals

VBA is an object-oriented programming language. The basic concept of object-oriented programming is that a software application (Excel in this case) consists of various individual objects. An Excel application contains workbooks, worksheets, cells, charts, pivot tables, shapes, and the list goes on. Each object has its own set of attributes, which are called properties , and its own set of actions, called methods .

You can think of this concept just as you would of the objects you encounter every day, such as your computer or your car. Each of those objects has attributes, such as height, weight, and color. They also have their own distinct actions. For instance, your computer boots up, and your program starts.

VBA objects also have their identifiable attributes and actions. A workbook, for example, is an object with attributes (properties), such as its name, the number of worksheets it contains, and the date it was created. A workbook object also has actions (methods) such as Open, Close, and Save.

In Excel, you deal with objects such as workbooks, worksheets, and ranges on a daily basis. You likely think of each of these “objects” as all part of Excel, not really separating them in your mind. However, Excel thinks about these internally as all part of a hierarchical model called the Excel Object Model. The Excel Object Model is a clearly defined set of objects that are structured according to the relationships among them.

Understanding objects

In the real world, you can describe everything you see as an object. When you look at your house, it is an object. Your house has rooms; those rooms are also separate objects. Those rooms may have closets. Those closets are likewise objects. As you think about your house, the rooms, and the closets, you may see a hierarchical relationship among them. Excel works in the same way.

In Excel, the Application object is the all-encompassing object—similar to your house. Inside the Application object, Excel has a workbook. Inside a workbook is a worksheet. Inside that is a range. These are all objects that live in a hierarchical structure.

To point to a specific object in VBA, you can traverse the object model. For example, to get to cell A1 on Sheet 1, you can enter this code:

Application.ThisWorkbook.Sheets("Sheet1").Range("A1").Select

In most cases, the object model hierarchy is understood, so you don't have to type every level. Entering this code also gets you to cell A1 because Excel infers that you mean the active workbook and the active sheet:

Range("A1").Select

Indeed, if you have your cursor already in cell A1, you can simply use the ActiveCellobject, negating the need to spell out the range.

Activecell.Select

Understanding collections

Many of Excel's objects belong to collections. Your house sits within a neighborhood, for example, which is a collection of houses called a neighborhood. Each neighborhood sits in a collection of neighborhoods called a city. Excel considers collections to be objects themselves.

In each Workbook object, you have a collection of Worksheets. The Worksheets collection is an object that you can call upon through VBA. Each worksheet in your workbook lives in the Worksheets collection.

If you want to refer to a worksheet in the Worksheets collection, you can refer to it by its position in the collection as an index number starting with 1 or by its name as quoted text. If you run these two lines of code in a workbook that has only one worksheet and that worksheet is called MySheet, they both do the same thing:

Worksheets(1).Select Worksheets("MySheet").Select

If you have two worksheets in the active workbook that have the names MySheetand YourSheet, in that order, you can refer to the second worksheet by typing either of these statements:

Worksheets(2).Select Worksheets("YourSheet").Select

If you want to refer to a worksheet in a workbook called MySheetin a particular workbook that is not active, you must qualify the worksheet reference and the workbook reference. Here's an example:

Workbooks("MyData.xlsx").Worksheets("MySheet").Select

Understanding properties

Properties are essentially the characteristics of an object. Your house has a color, a square footage, an age, and so on. Some properties can be changed, like the color of your house. Other properties can't be changed, like the year your house was constructed.

Likewise, an object in Excel, like the Worksheetobject, has a sheet name property that can be changed, and a Rows.Countrow property that cannot.

You refer to the property of an object by referring to the object and then the property. For instance, you can change the name of your worksheet by changing its Nameproperty.

In this example, you are renaming Sheet1to MySheet:

Sheets("Sheet1").Name = "MySheet"

Some properties are read-only, which means you can't assign a value to them directly—for instance, the Textproperty of a cell. The Textproperty gives you the formatted appearance of value in a cell, but you cannot overwrite or change it.

Some properties have arguments that further specify the property value. For instance, this line of code uses the RowAbsoluteand ColumnAbsolutearguments to return the address of cell A1 as an absolute reference ( $A$ 1).

MsgBox Range("A1").Address(RowAbsolute:=True, ColumnAbsolute:=True)

Specifying properties for the active object

When you're working with Excel, only one workbook at a time can be active. In that workbook, only one sheet can be active. And if the sheet is a worksheet, one cell is the active cell (even if a multicell range is selected). VBA knows about active workbooks, worksheets, and cells, and it lets you refer to these active objects in a simplified manner.

This method of referring to objects is often useful because you won't always know the exact workbook, worksheet, or range on which you want to operate. VBA makes object referencing easy by providing properties of the Applicationobject. For example, the Applicationobject has an ActiveCellproperty that returns a reference to the active cell. The following instruction assigns the value 1to the active cell:

ActiveCell.Value = 1

In the preceding example, we omitted the reference to the Applicationobject and to the active worksheet because both are assumed. This instruction will fail if the active sheet isn't a worksheet. For example, if VBA executes this statement when a chart sheet is active, the procedure halts and you get an error message.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Excel 2019 Power Programming with VBA»

Представляем Вашему вниманию похожие книги на «Excel 2019 Power Programming with VBA» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Michael Alexander - Confessions of a Male Nurse
Michael Alexander
Michael Savage - Abuse of Power
Michael Savage
Michael C. Hyter - The Power of Choice
Michael C. Hyter
Elizabeth Power - A Clash with Cannavaro
Elizabeth Power
Michael Alexander Müller - Ein Tropfen in der Zeit
Michael Alexander Müller
Michael Alexander Müller - Aufbruch / Inqilab
Michael Alexander Müller
Michael Alexander Müller - Prinzenpack
Michael Alexander Müller
Michael Carroll - Absolute Power
Michael Carroll
Michael Grant - The Power
Michael Grant
Отзывы о книге «Excel 2019 Power Programming with VBA»

Обсуждение, отзывы о книге «Excel 2019 Power Programming with VBA» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x