TAILIEUCHUNG - Excel 2002 Power Programming with VBA phần 5

Nếu đó là không đủ, tuy nhiên, bạn có thể tạo ra chức năng tùy chỉnh bằng cách sử dụng VBA. Với tất cả các chức năng có sẵn trong Excel và VBA, bạn có thể tự hỏi tại sao bạn sẽ cần phải tạo ra các chức năng mới. Câu trả lời: để đơn giản hóa công việc của bạn. Với một chút kế hoạch, chức năng tùy chỉnh là rất hữu ích trong công thức bảng tính | 358 Part IV Working with UserForms Table 12-1 Codes to Determine the Data Type Returned by Excel s InputBox Method Code Meaning 0 A formula 1 A number 2 A string text 4 A logical value True or False 8 A cell reference as a range object 16 An error value such as N A 64 An array of values Excel s InputBox method is quite versatile. To allow more than one data type to be returned use the sum of the pertinent codes. For example to display an input box that can accept text or numbers set type equal to 3 that is 1 2 or number plus text . If you use 8 for the type argument the user can enter a cell or range address manually or point to a range in the worksheet. The EraseRange procedure which follows uses the InputBox method to allow the user to select a range to erase see Figure 12-2 . The user can either type the range address manually or use the mouse to select the range in the sheet. The InputBox method with a type argument of 8 returns a Range object note the Set keyword . This range is then erased by using the Clear method . The default value displayed in the input box is the current selection s address. The On Error statement ends the procedure if the input box is canceled. Sub EraseRange Dim UserRange As Range DefaultRange On Error goto Canceled Set UserRange _ Prompt Range to erase _ Title Range Erase _ Default DefaultRange _ Type 8 Canceled End Sub Chapter 12 Custom Dialog Box Alternatives 359 Figure 12-2 Using the InputBox method to specify a range Yet another advantage of using Excel s InputBox method is that Excel performs input validation automatically. In the GetRange example if you enter something other than a range address Excel displays an informative message and lets the user try again see Figure 12-3 . Figure 12-3 Excel s InputBox method performs validation automatically. VBA s MsgBox Function VBA s MsgBox function is an easy way to display a message to the user or to get a simple .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.