Using the Visual Basic Editor
Số trang: 18
Loại file: pdf
Dung lượng: 42.58 KB
Lượt xem: 16
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Using the Visual Basic Editor Before you can write VBA macros, you need an editor. Outlook, like the other Office applications, includes the Visual Basic Editor.
Nội dung trích xuất từ tài liệu:
Using the Visual Basic Editor[ Team LiB ]Using the Visual Basic EditorBefore you can write VBA macros, you need an editor. Outlook, like the other Officeapplications, includes the Visual Basic Editor. Open the editor interface by choosingTools, Macro, Visual Basic Editor or by pressing Alt+F11 on your keyboard. The Visual Basic Editor should be installed by default with a typical or complete installation. If its not available, youll have to use the Add/Remove Programs applet in Windows Control Panel and change your installed features.The Visual Basic Editor has all the tools youll need. Use the Project Explorer to see allthe modules youve associated with Outlook and the Properties window to add or changeproperties, including the project name and other properties.Type your code in the large window. Selecting Application in the Object drop-down list,shown as (General) in Figure 21.1, lists the available procedures in the right field andautomatically enters the selection in the code window. Figure 21.1. Use the Visual Basic Editor to develop your macros.The Visual Basic Editor interface includes the Project and Properties browsers, the maincode window, and the Standard toolbar. Right-click on the toolbars and show the Edit andDebug toolbars. Figures 21.2 through 21.4 detail the buttons found on these toolbars.Figure 21.2. The Standard toolbar has the standard Windows commands along with commands you can use to switch back to Outlook, select a module, form, or class, run your code, and show the object browser and control toolbox. Figure 21.4. The Debug toolbar is used for your debugging code. Use Run, Break, and Reset to start and stop the macro, and use Step In, Out, and Over to run thecode line by line or skip lines. Use the windows and watches and see the results your code returns. Figure 21.3. Use the Edit toolbar to provide information about properties and methods in your code, toggle breakpoints, change indentation, comment code blocks, and use bookmarks while writing and debugging your code.One of the most important features of the VB Editor is the Object Browser. Using theObject Browser, you can see all the properties, methods, and objects referenced in yourproject and available for you to use (see Figure 21.5). Figure 21.5. Use the Object Browser to view the object model and libraries referenced in your project. Select the library from the Project/Library list or enter search words in the Search field. Add or remove libraries from your project using Tools, References. Only references that have checkmarks are available for use in your project.Now that you know where to find the main parts of the editor, its time to write yourcode. The general steps are 1. Make a copy of or back up your mailbox before testing your code. Although its safer to test against a test account, the results might be different when you test against real data and its very risky if your code doesnt work correctly. Backups are especially important when youre writing code that changes items. 2. Name the Sub procedure. This is the project name youll look for when you run the macro from Tools, Macros, Macros. Dont use spaces and keep the name short. 3. Declare your objects, strings, and so on. You need to define the name and data type of a variable used in your code. 4. Type your code in the module. 5. Test your code to see if it works without error. Use the Save button often and either exit Outlook and confirm the prompt to save the VBAProject.OTM, or copy the code to Notepad or an Outlook post form and then save. If Outlook hangs on your code, you could lose your work.Task: Create Your First MacroWhen there is a feature Microsoft forgot that youd like to have in Outlook, many timesyou can create a macro yourself. Some macros are complex, but others just look complex.The macro were going to create falls into the second group; it looks complex, but itsreally simple.This macro provides a time-saving feature that Outlook should have, but doesnt: theability to easily save attachments to a specific folder on your hard drive and then deletethe attachment from the message. In addition, we add a clickable link pointing to theattachment on the bottom of the message. Attachments that are blocked by Outlooks Attachment Security features will not be saved or removed from the message.Before you can enter VBA code, you have to open the VB Editor, using the Tools,Macros, Visual Basic Editor menu selection. If you prefer keyboard shortcuts, useAlt+F11. 1. Click on ThisOutlookSession to open it in the code window, if its not already open. 2. Choose ...
Nội dung trích xuất từ tài liệu:
Using the Visual Basic Editor[ Team LiB ]Using the Visual Basic EditorBefore you can write VBA macros, you need an editor. Outlook, like the other Officeapplications, includes the Visual Basic Editor. Open the editor interface by choosingTools, Macro, Visual Basic Editor or by pressing Alt+F11 on your keyboard. The Visual Basic Editor should be installed by default with a typical or complete installation. If its not available, youll have to use the Add/Remove Programs applet in Windows Control Panel and change your installed features.The Visual Basic Editor has all the tools youll need. Use the Project Explorer to see allthe modules youve associated with Outlook and the Properties window to add or changeproperties, including the project name and other properties.Type your code in the large window. Selecting Application in the Object drop-down list,shown as (General) in Figure 21.1, lists the available procedures in the right field andautomatically enters the selection in the code window. Figure 21.1. Use the Visual Basic Editor to develop your macros.The Visual Basic Editor interface includes the Project and Properties browsers, the maincode window, and the Standard toolbar. Right-click on the toolbars and show the Edit andDebug toolbars. Figures 21.2 through 21.4 detail the buttons found on these toolbars.Figure 21.2. The Standard toolbar has the standard Windows commands along with commands you can use to switch back to Outlook, select a module, form, or class, run your code, and show the object browser and control toolbox. Figure 21.4. The Debug toolbar is used for your debugging code. Use Run, Break, and Reset to start and stop the macro, and use Step In, Out, and Over to run thecode line by line or skip lines. Use the windows and watches and see the results your code returns. Figure 21.3. Use the Edit toolbar to provide information about properties and methods in your code, toggle breakpoints, change indentation, comment code blocks, and use bookmarks while writing and debugging your code.One of the most important features of the VB Editor is the Object Browser. Using theObject Browser, you can see all the properties, methods, and objects referenced in yourproject and available for you to use (see Figure 21.5). Figure 21.5. Use the Object Browser to view the object model and libraries referenced in your project. Select the library from the Project/Library list or enter search words in the Search field. Add or remove libraries from your project using Tools, References. Only references that have checkmarks are available for use in your project.Now that you know where to find the main parts of the editor, its time to write yourcode. The general steps are 1. Make a copy of or back up your mailbox before testing your code. Although its safer to test against a test account, the results might be different when you test against real data and its very risky if your code doesnt work correctly. Backups are especially important when youre writing code that changes items. 2. Name the Sub procedure. This is the project name youll look for when you run the macro from Tools, Macros, Macros. Dont use spaces and keep the name short. 3. Declare your objects, strings, and so on. You need to define the name and data type of a variable used in your code. 4. Type your code in the module. 5. Test your code to see if it works without error. Use the Save button often and either exit Outlook and confirm the prompt to save the VBAProject.OTM, or copy the code to Notepad or an Outlook post form and then save. If Outlook hangs on your code, you could lose your work.Task: Create Your First MacroWhen there is a feature Microsoft forgot that youd like to have in Outlook, many timesyou can create a macro yourself. Some macros are complex, but others just look complex.The macro were going to create falls into the second group; it looks complex, but itsreally simple.This macro provides a time-saving feature that Outlook should have, but doesnt: theability to easily save attachments to a specific folder on your hard drive and then deletethe attachment from the message. In addition, we add a clickable link pointing to theattachment on the bottom of the message. Attachments that are blocked by Outlooks Attachment Security features will not be saved or removed from the message.Before you can enter VBA code, you have to open the VB Editor, using the Tools,Macros, Visual Basic Editor menu selection. If you prefer keyboard shortcuts, useAlt+F11. 1. Click on ThisOutlookSession to open it in the code window, if its not already open. 2. Choose ...
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin tin học văn phòng mircrosoft office outlook 2003 Using the Visual Basic EditorGợi ý tài liệu liên quan:
-
52 trang 429 1 0
-
73 trang 427 2 0
-
Nhập môn Tin học căn bản: Phần 1
106 trang 327 0 0 -
Giáo trình Tin học văn phòng: Phần 2 - Bùi Thế Tâm
65 trang 314 0 0 -
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 312 0 0 -
74 trang 294 0 0
-
96 trang 291 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 288 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 278 0 0 -
Giáo trình Tin học MOS 1: Phần 1
58 trang 275 0 0