Excel 2002 Power Programming with VBA phần 6

và các thủ tục VBA. Thông thường, ví dụ, bạn có thể tạo ra một chức năng tùy chỉnh mà có thể rút ngắn đáng kể công thức của bạn. Và công thức ngắn hơn dễ đọc hơn và dễ dàng hơn để làm việc với. Tôi cũng nên chỉ ra, tuy nhiên, có chức năng tùy chỉnh được sử dụng trong công thức của bạn thường chậm hơn nhiều so | 456 Part IV Working with UserForms Figure 15-8 This modeless dialog box remains visible while the user continues working. Refer to Chapter 18 for additional information about events. The event-handler procedures follow Private Sub Workbook_SheetSelectionChange _ ByVai Sh As Object ByVai Target As Range Call UpdateBoX End Sub Private Sub Workbook_SheetActivate ByVal Sh As Object Call UpdateBox End Sub These procedures call the UpdateBox procedure which follows Sub UpdateBox With UserForml Make sure a worksheet is active If TypeName ActiveSheet Worksheet Then . N A . N A . N A Exit Sub End If 458 Part IV Working with UserForms Figure 15-9 shows a much more sophisticated version of this example it s also on the CD-ROM . This version displays quite a bit of additional information about the selected cell. Long-time Excel users may notice the similarity with the Info window a feature that was removed from Excel several years ago. The code is too lengthy to display here but you can view the well-commented code in the example workbook. Figure 15-9 This UserForm displays information about the active cell. Multiple Buttons One Event-Handler Every CommandButton on a UserForm must have its own procedure to handle its Click event. For example if you have two CommandButtons you ll need at least two event-handler procedures Private Sub Code goes End Sub Private Sub Code goes End Sub CommandButton1_Click here CommandButton2_Click here In other words you cannot assign a macro to execute when any CommandButton is clicked. Each Click event-handler is hard-wired to its CommandButton. You can however have each event-handler call another all-inclusive macro in the eventhandler procedures but you ll need to pass an argument to indicate which button was clicked. In the following examples clicking either CommandButtonl or CommandButton2 both execute the ButtonClick procedure and the single argument tells the ButtonClick procedure which

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
103    161    5    27-07-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.