我正在使用一個帶有按鈕的表單從Intranet下載工作表,並使用來源工作表中的數據填充此目的工作表。這部分工作:數據填充,形式卸載,腳本停止,我已經把我的目標表作爲活動屏幕。
現在出現這個問題:我可以選擇單元格,但不能在Excel中使用任何功能,不能在快速訪問功能區上按任何按鈕,如文件,主頁或保存。推ESC
沒有幫助。解凍Excel的唯一方法是在隨機單元格的某處按下鼠標右鍵。它'解鎖'excel,我可以進入文件菜單。我不知道要去哪裏看。我認爲這是一個小事,但不知道它是什麼。運行代碼後Excel菜單欄凍結。點擊右鍵後解凍
這是代碼(跳轉用於單個或多個項目。如果它是1個項目我跳過循環也許有這個更好的選擇。):
Private Sub genbutton_Click()
On Error GoTo 0
Dim startsheet As String
startsheet = ActiveSheet.Name
roww = ActiveCell.Row
Set Source = ActiveWorkbook.ActiveSheet
'search for column in source sheet
kolommaint = kolomnaam2("Maintenance Plan")
kolomfloc = kolomnaam2("Functional Location")
kolomdescrip = kolomnaam2("Maintenance item description")
kolomequip = kolomnaam2("Equipment")
'find last row on data source page
With ActiveSheet
lastrow = .Cells(.Rows.Count, kolommaint).End(xlUp).Row
End With
Set destinationsheet = Workbooks.Open("http:// sheet on intranet.xlsm")
'find first data row on destination sheet
Dim FindString As String
Dim Rng As Range
FindString = "Action"
With destinationsheet.Sheets("Data input").Range("A:A")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
datarij = ActiveCell.Row + 1
End If
End With
'make a jump to avoid loop if only 1 item is needed
If callsingle.Value = True Then
i = roww
If Source.Range(kolommaint & i).Value = "" Then
GoTo verdergaan
End If
GoTo jump
End If
For i = eerstedatarij To lastrow
jump:
'skip row if empty
If Source.Rows(i).Hidden = True Then
GoTo verdergaan
End If
destinationsheet.Sheets("Data input").Range("A" & datarij).Value = "Release Call"
destinationsheet.Sheets("Data input").Range("B" & datarij).Value = Source.Range(kolommaint & i).Value
destinationsheet.Sheets("Data input").Range("C" & datarij).Value = "PM"
destinationsheet.Sheets("Data input").Range("E" & datarij).Value = Source.Range(kolomdescrip & i).Value
destinationsheet.Sheets("Data input").Range("F" & datarij).Value = Source.Range(kolomdescrip & i).Value
destinationsheet.Sheets("Data input").Range("G" & datarij).Value = Source.Range(kolomfloc & i).Value
destinationsheet.Sheets("Data input").Range("H" & datarij).Value = Source.Range(kolomequip & i).Value
datarij = datarij + 1
'make jump if single item is used
If callsingle.Value = True Then
GoTo jump2
End If
verdergaan:
Next i
jump2:
destinationsheet.Sheets("Data input").Range("A13").Select
Set Source = Nothing
Set destinationsheet= Nothing
Unload Me
End Sub
我「M用下面的代碼解凍的Excel現在:
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Public Sub RightDown()
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub
你不能「跳轉」到For循環中。儘量避免使用GoTo,除了錯誤處理。如果你想停止一個For循環,只需使用「退出」。 –
我在代碼註釋中輸入了一個類型。它更多的是爲了不進入循環而跳躍。但感謝評論,我將嘗試使用Exit For。我使用跳轉功能更多,但從未遇到凍結屏幕的問題。 – bob