在工具——宏——vba編輯器裡 1、插入一個窗體UserForm1,新增兩個標籤、兩個文字框、兩個命令按鈕,輸入如下程式碼: Private Sub CommandButton1_Click() If Val(TextBox1) <= 0 Or Val(TextBox2) <= 0 Then MsgBox "輸入錯" Exit Sub End If Cells(1, 1) = "學生序號" For i = 1 To TextBox1.Text Cells(i + 1, 1) = "s" & i Next i For i = 1 To TextBox2.Text Cells(1, i + 1) = "p" & i Next i Me.Hide End Sub Private Sub CommandButton2_Click() Me.Hide End Sub 2、插入一個模組輸入如下程式碼 Sub getps() UserForm1.Show End Sub 3、在工具欄上點右鍵,選自定義;在命令標籤裡找到宏,把自定義按鈕拖動到工具欄中 4、點自定義的按鈕,指定宏
在工具——宏——vba編輯器裡 1、插入一個窗體UserForm1,新增兩個標籤、兩個文字框、兩個命令按鈕,輸入如下程式碼: Private Sub CommandButton1_Click() If Val(TextBox1) <= 0 Or Val(TextBox2) <= 0 Then MsgBox "輸入錯" Exit Sub End If Cells(1, 1) = "學生序號" For i = 1 To TextBox1.Text Cells(i + 1, 1) = "s" & i Next i For i = 1 To TextBox2.Text Cells(1, i + 1) = "p" & i Next i Me.Hide End Sub Private Sub CommandButton2_Click() Me.Hide End Sub 2、插入一個模組輸入如下程式碼 Sub getps() UserForm1.Show End Sub 3、在工具欄上點右鍵,選自定義;在命令標籤裡找到宏,把自定義按鈕拖動到工具欄中 4、點自定義的按鈕,指定宏