Showing posts with label Dialog Box. Show all posts
Showing posts with label Dialog Box. Show all posts

Understanding Macro Security

April 30, 2017 Add Comment

Macro security is a key feature in Excel. The reason is that VBA is a powerful language — so powerful that even a simple macro can do serious damage to your computer. 

A macro can delete files, send information to other comput-ers, and even destroy Windows so that you can’t even start your system.

The macro security features in Excel 2007 and Excel 2010 were created to help prevent these types of problems. 

Figure 2-6 shows the Macro Settings section of the Trust Center dialog box. To display this dialog box, choose Developer ➪ Codem ➪ Macro Security. 

By default, Excel uses the Disable All Macros with Notification section. With this setting in effect, if you open a workbook that contains macros (and the file is not digitally “signed” or stored in a trusted location), Excel displays a warning like the one in Figure 2-7. If you are certain that the workbook comes from a trusted source, click Enable Macros, and the macros will be enabled.


You see the pop-up box in Figure 2-7 only if the VBE is open. Otherwise, Excel displays an eye-catching Security Warning above the Formula bar. You can click the button to enable the macros.


If you use Excel 2010, Excel will remember if you’ve designated a workbook to be safe. So, the next time you open it, you won’t see the Security Warning.
That’s not the case with Excel 2007 though. You’ll get the security warning every time — unless you store that workbook in a trusted location.

Perhaps the best way to handle macro security is to designate one or more folders as trusted locations. All the workbooks in a trusted location are opened without a macro warning. You designate trusted folders in the Trusted Locations section of the Trust Center dialog box.

If you want to find out what the other macro security settings imply, press F1 while the Macro Settings section of the Trust Center dialog box is in view.
The Help screen opens and the subject “Enable or disable macros in Office documents” is shown in the Help window.

The MsgBox Function

February 24, 2017 Add Comment



You’re probably already familiar with the VBA MsgBox function — I use it quite a bit in the examples throughout this book. 

The MsgBox function, which accepts the arguments shown in Table 15-1, is handy for displaying information and getting simple user input. It’s able to get user input because it’s a function. 

A function, as you recall, returns a value. In the case of the Msgbox function, it uses a dialog box to get the value that it returns. Keep reading to see exactly how it works.


Here’s a simplified version of the syntax for the MsgBox function:
MsgBox(prompt[, buttons][, title])
You can use the MsgBox function in two ways:
  1. To simply show a message to the user. In this case, you don’t care about the result returned by the function.
  2. To get a response from the user. In this case, you do care about the result returned by the function. The result depends on the button that the user clicks.
If you use the MsgBox function by itself, don’t include parentheses around the arguments. The following example simply displays a message and does not return a result. When the message is displayed, the code stops until the user clicks OK.
Sub MsgBoxDemo()
MsgBox “Click OK to begin printing.”
Sheets(“Results”).PrintOut
End Sub

Figure 15-1 shows how this message box looks.

You can also use the MsgBox function result without using a variable, as the following example demonstrates:
Sub GetAnswer2()
If MsgBox(“Continue?”, vbYesNo) = vbYes Then
         ‘ ...[code if Yes is clicked]...
Else
          ‘ ...[code if Yes is not clicked]...
End If

End Sub