How to make a small program in excel: first open the VBE interface and click [User Form]; then create a command button and change the display content of the command button; then double-click the user form and replace the original code; Finally save the file and enable it.
How to use a small program in excel:
1. Press Alt F11 in Excel to open the VBE interface , as shown in the figure below:
2. Click "Insert", "UserForm", as shown in the figure below:
3. Then click "Command Button" and drag on the user form to create a command button, as shown below:
4. Press Press F4, and in the Caption property, change the display content of the command button, as shown below:
5. Then double-click the user form and replace the original code with the following code
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If X > 0 Then Me.Left = Application.RandBetween(0, 800) Me.Top = Application.RandBetween(0, 350) End If End Sub
As shown in the figure below:
6. Double-click "Thisworkbook" on the right and copy the following code, as shown in the figure below:
Private Sub Workbook_Open() UserForm1.Show End Sub
7. Save the Excel file as "Excel macro-enabled workbook", as shown below:
8. Close and then open the Excel file, you can see the written program, as shown below:
Related learning recommendations: excel basic tutorial
The above is the detailed content of How to make a small program in excel?. For more information, please follow other related articles on the PHP Chinese website!