No. Recording is useful for very simple macros only. Macros that use variables , looping, or any other type of program flow changes cannot be recorded. You can, however, often take advantage of the macro recorder to write some parts of your code or to discover the relevant properties or methods .
Yes, that's a problem with the initial release of Excel 2007. Perhaps it will be fixed in a later update.
Consider storing those general-purpose macros in your Personal Macro Workbook. This is a (normally) hidden workbook that is loaded automatically by Excel. When you record a macro, you have the option of recording it to your Personal Macro Workbook. The file, Personal.xlsb , is stored in your \XLStart directory.
The Personal.xlsb file doesn't exist until you record a macro to it.
Several third-party password-cracking products exist. Use a Web search engine to search for Excel password. The existence of these products should tell you that Excel passwords are not very secure.
You can't. The protection elements of a VBA project are not exposed in the object model. Most likely, this was done to make it more difficult for password-cracking software.
If Option Explicit is included at the top of a module, it means that you must declare every variable before you use it in a procedure (which is a good idea). If you don't want this line to appear in new modules, activate the VBE, choose Tools Options, click the Editor tab, and clear the Require Variable Declaration check box. Then you can either declare your variables or let VBA handle the data typing automatically.
VBA uses color to differentiate various types of text: comments, keywords, identifiers, statements with a syntax error, and so on. You can adjust these colors and the font used by choosing the Tools Options command (Editor Format tab) in the VBE.
Yes. The following code deletes Module1 from the active workbook:
With ActiveWorkbook.VBProject .VBComponents.Remove .VBComponents("Module1") End With
This might not work with Excel 2002 and later. See the next question.
Excel 2002 introduced a new setting: Trust Access to Visual Basic Project. By default, this setting is turned off. To change it in Excel 2007, choose Office Excel Options Trust Center. Click the Trust Center Settings button to display the Trust Center dialog box. Click the Macro Settings tab and place a check mark next to Trust Access to the VBA Project Object Model.
The ability to change the security level using VBA would pretty much render the entire macro security system worthless. Think about it.
When protecting a worksheet using VBA code, you can use a statement such as
ActiveSheet.Protect UserInterfaceOnly:=True
This causes the sheet to be protected, but your macros can still make changes to the sheet. It's important to understand that this setting is not saved with the workbook. When the workbook is re-opened, you'll need to re-execute the statement in order to reapply the UserInterfaceOnly protection.
In the VBE, activate the project that corresponds to the workbook. Examine all the code modules (including the ThisWorkbook code module) and look for VBA code that is not familiar to you. Usually, virus code will not be formatted well and will contain many unusual variable names . Another option is to use a commercial virus-scanning program.
VBA is probably interpreting the ampersand as a type-declaration character. Make sure that you insert a space before and after the concatenation operator.
The line continuation sequence is actually two characters : a space followed by an underscore.
The error-handling procedures won't work if the user has the Break on All Errors option set. This option is available in the Options dialog box (General tab) in the VBE. Unfortunately, you can't change this setting with VBA.