无法从用户表单激活工作表

时间:2018-08-31 06:05:15

标签: excel vba excel-vba

现在,我正在尝试运行代码,突然我的工作表激活行中出现错误。昨天,它运行良好,没有任何问题。直到现在,我仍然无法找到错误。请参考下面的代码。如果有人能给我关于如何运行代码而不会出错的建议,我将不胜感激。

对于下面的命令按钮,单击时出现错误。

Private Sub cmdsubmit_Click()
Dim i As Integer
Dim Submittedtask As String

    Worksheets("Submittedtask").Activate  'this line i am getting error 

    'position cursor in the correct cell A8.
    ActiveSheet.Range("A8").Select
 
    i = 1 'set as the first ID

    'validate first three controls have been entered...
    If Me.txtProject.Text = Empty Then 'Firstname
        MsgBox "Please enter firstname.", vbExclamation
        Me.txtProject.SetFocus 'position cursor to try again
        Exit Sub 'terminate here - why continue?
    End If


    'if all the above are false (OK) then carry on.
    'check to see the next available blank row start at cell A2...
    Do Until ActiveCell.Value = Empty
        ActiveCell.Offset(1, 0).Select 'move down 1 row
        i = i + 1 'keep a count of the ID for later use
    Loop

    'Populate the new data values into the 'Data' worksheet.
    ActiveCell.Value = i 'Next ID number
    ActiveCell.Offset(0, 2).Value = Me.txtProject.Text 'set col B
    ActiveCell.Offset(0, 3).Value = Me.txtEnia.Text 'set col C
    ActiveCell.Offset(0, 1).Value = Me.DTPicker1.Value


    'Clear down the values ready for the next record entry...
    Me.txtProject.Text = Empty
    Me.txtEnia.Text = Empty

    Me.cboLs.Set Focus 'positions the cursor for next record entry
    
    
End Sub

0 个答案:

没有答案