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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

Recording macros with relative references

In the context of Excel macros, relative means relative to the currently active cell . Thus, you should use caution with your active cell choice—both when you record the relative reference macro and when you run it.

First, make sure that the Chapter 2 Sample.xlsmfile is open. (This file is available on this book's companion website.) Then use the following steps to record a relative-reference macro:

1 Select the Use Relative References toggle button from the Developer tab, as shown in Figure 2.5. FIGURE 2.5 Recording a macro with relative references

2 Before recording, make sure that cell A1 is selected.

3 Select Record Macro from the Developer tab.

4 Name the macro AddTotalRelative.

5 Choose This Workbook in the Store Macro In drop-down.

6 Click OK to start recording.

7 Select cell A16 and type Total in the cell.

8 Select the first empty cell in Column D (D16), type = COUNTA(D2:D15), and then press Enter.

9 Click Stop Recording on the Developer tab to stop recording the macro.

At this point, you have recorded two macros. Take a moment to examine the code for your newly created macro.

Select Macros from the Developer tab to open the Macro dialog box. Here, choose the AddTotalRelativemacro and click Edit.

Again, this opens the Visual Basic Editor to show you the code that was written when you recorded your macro. This time, your code looks something like the following:

Sub AddTotalRelative() ActiveCell.Offset(15, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "Total" ActiveCell.Offset(0, 3).Range("A1").Select ActiveCell.FormulaR1C1 = "=COUNTA(R[-14]C:R[-1]C)" End Sub

Notice that there are no references to any specific cell ranges at all (other than the starting point "A1"). Let's take a moment to look at what the relevant parts of this VBA code really mean.

Notice that in line 2, Excel uses the Offsetproperty of the active cell. This property tells the cursor to move a certain number of cells up or down and a certain number of cells left or right.

The Offsetproperty code tells Excel to move 15 rows down and 0 columns across from the active cell (in this case, A1). There's no need for Excel to select a cell explicitly, as it did when recording an absolute reference macro.

To see this macro in action, delete the total row and do the following:

1 Select cell A1.

2 Select Macros from the Developer tab.

3 Find and select the AddTotalRelative macro.

4 Click the Run button.

5 Now select cell F1.

6 Select Macros from the Developer tab.

7 Find and select the AddTotalRelative macro.

8 Click the Run button.

Notice that this macro, unlike your previous macro, works on both sets of data. Because the macro applies the totals relative to the currently active cell, the totals are applied correctly.

For this macro to work, you simply need to ensure that

You've selected the correct starting cell before running the macro.

The block of data has the same number of rows and columns as the data on which you recorded the macro.

Ideally, this simple example has given you a firm grasp of macro recording of both absolute and relative references.

Other macro recording concepts

At this point, you should feel comfortable recording your own Excel macros. Next are some of the other important concepts you'll need to keep in mind when writing or recording macros.

By default, Excel workbooks are given the standard file extension .xlsx. Be aware that files with the .xlsxextension cannot contain macros. If your workbook contains macros and then you save that workbook as an .xlsxfile, all VBA code is removed automatically. Luckily, Excel will warn you that your macro content will be removed when saving a workbook with macros as an .xlsxfile.

If you want to retain the macros, you must save your file as an Excel Macro-Enabled Workbook. This gives your file an .xlsmextension. The idea is that all workbooks with an .xlsxfile extension are automatically known to be safe, whereas you can recognize .xlsmfiles as a potential threat.

Alternatively, you can save your workbook as an Excel 97-2003 Workbook (with the .xlsextension). The .xlsfile type can contain macros, but it doesn't support some of the modern features of Excel such as conditional formatting icons and pivot table slicers. You would typically use this file type only if there is a specific reason, such as that you need to have your workbook interact with an add-in that works only with .xlsfiles.

Macro security in Excel

With the release of Office 2010, Microsoft introduced significant changes to its Office security model. One of the most significant changes is the concept of trusted documents. Without getting into the technical minutiae, a trusted document is essentially a workbook that you have deemed safe by enabling macros.

If you open a workbook that contains macros, you will see a yellow bar message under the Ribbon stating that macros (active content) have, in effect, been disabled.

If you click Enable, it automatically becomes a trusted document. This means that you no longer are prompted to enable the content as long as you open that file on your computer. The basic idea is that if you told Excel that you “trust” a particular workbook by enabling macros, it is highly likely that you will enable macros each time you open it. Thus, Excel remembers that you've enabled macros before and inhibits any further messages about macros for that workbook.

This is great news for you and your clients. After enabling your macros just one time, they won't be annoyed by the constant messages about macros, and you won't have to worry that your macro-enabled dashboard will fall flat because macros have been disabled.

Trusted locations

If the thought of any macro message coming up (even one time) unnerves you, you can set up a trusted location for your files. A trusted location is a directory that is deemed a safe zone where only trusted workbooks are placed. A trusted location allows you and your clients to run a macro-enabled workbook with no security restrictions as long as the workbook is in that location.

To set up a trusted location, follow these steps:

1 Select the Macro Security button on the Developer tab. This activates the Trust Center dialog box.

2 Click the Trusted Locations button. This opens the Trusted Locations menu (see Figure 2.6), which shows you all the directories that are considered trusted. FIGURE 2.6 The Trusted Locations tab allows you to add directories that are considered trusted.

3 Click the Add New Location button.

4 Click Browse to find and specify the directory that will be considered a trusted location.

After you specify a trusted location, any Excel file that is opened from this location will have macros automatically enabled.

Storing macros in your Personal Macro Workbook

Most user-created macros are designed for use in a specific workbook, but you may want to use some macros in all of your work. You can store these general-purpose macros in the Personal Macro Workbook so that they're always available to you. The Personal Macro Workbook is loaded whenever you start Excel. This file, named Personal.xlsb, doesn't exist until you record a macro using Personal Macro Workbook as the destination.

To record the macro in your Personal Macro Workbook, select the Personal Macro Workbook option in the Record Macro dialog box before you start recording. This option is in the Store Macro In drop-down list (refer to Figure 2.1in the section “Creating Your First Macro”).

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

Интервал:

Закладка:

Сделать

Похожие книги на «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