我正在使用一个带有按钮的表单从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