XL: How to Use a Custom Dialog Box for Data Entry |
Q141289
The following Microsoft Visual Basic for Applications procedure uses edit boxes on a custom dialog sheet to receive your data and place that data on a worksheet.
After you have entered the data into the edit boxes, press ENTER or click the OK button on the custom dialog box to enter the data on the worksheet, reinitialize the dialog box, and display it for the next record. Click Cancel to halt the macro.
http://www.microsoft.com/partner/referral/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://support.microsoft.com/directory/overview.aspTo create the procedure, follow these steps:
A1: First Name B1: Last Name C1: Department
' Dimension the variables to be used to control the procedures.
Dim StopFlag As Integer 'Used to control the loop
Dim RowNum As Single 'Used to determine data input line
' Controlling procedure that sets up initial values of variables and
' holds the loop that calls the actual working procedures.
Sub Main_Procedure()
' Determine the current number of rows on the Data worksheet.
RowNum = ThisWorkbook.Worksheets("data").Range("a1" _
).CurrentRegion.Rows.Count
' Set the flag used to control the loop to it's initial value.
StopFlag = 0
' This loop blanks the edit boxes on the dialog sheet, shows the
' dialog box, and enters the data to the worksheet.
Do Until StopFlag = 1
Initialize_Dialog
DialogSheets("Dialog").Show
Enter_Data_on_Worksheet
Loop
End Sub
' This procedure sets the edit boxes on the dialog sheet as empty.
Sub Initialize_Dialog()
With DialogSheets("Dialog")
.EditBoxes("fname").Text = ""
.EditBoxes("lname").Text = ""
.EditBoxes("dept").Text = ""
End With
End Sub
' Place data in worksheet on row indicated by RowNum.
Sub Enter_Data_on_Worksheet()
With Worksheets("Data")
.Range("a1").Offset(RowNum, 0) = _
DialogSheets("Dialog").EditBoxes("fname").Text
.Range("a1").Offset(RowNum, 1) = _
DialogSheets("Dialog").EditBoxes("lname").Text
.Range("a1").Offset(RowNum, 2) = _
DialogSheets("Dialog").EditBoxes("dept").Text
End With
RowNum = RowNum + 1 ' Shift indicator to next line.
End Sub
Sub Stop_Loop()
StopFlag = 1 ' Set flag to halt loop.
End Sub Additional query words: 5.00a 5.00c
Keywords : kbcode kbprogramming
Issue type : kbhowto
Technology : kbHWMAC kbOSMAC kbExcelSearch kbExcel700 kbExcel500 kbExcel95Search kbExcelMacsearch kbExcel500Mac kbExcel500aMac kbExcel500c kbExcel500NT
|
Last Reviewed: December 31, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |