问题:在代码运行完毕之前,工作簿无法打开。
详细信息:我有一个循环,要求用户打开另一个文件,以便代码继续。该文件必须从互联网上下载并打开。如果文件未打开,则会出现一个msgbox,要求用户打开该文件。即使我下载文件并打开它,它也不会打开,直到所有其他代码都被执行完毕。
我的想法:也许有类似于"刷新",它会更新当前状态。我应该在下面的现有代码中添加一些东西来刷新excel工作簿并查看是否还有其他事情发生。
以下代码:(代码很好,适用于我需要的,问题是工作簿在所有其他代码完成之前不会打开):
Private Function WorkbookActive() As Boolean
' Loop until the correct workbook is open
Do Until WorkbookActive = True
On Error Resume Next
If Workbooks("Rapport.csv") Is Nothing Then
If MsgBox("[Rapport.csv] - Workbook is currently not open." & vbNewLine & "Please download and open [Rapports.csv] and press OK", vbOKCancel, "Workbook not open") = vbCancel Then Exit Do
WorkbookActive = False
ElseIf Not Workbooks("Rapport.csv") Is Nothing Then
WorkbookActive = True
End If
Loop
End Function
答案 0 :(得分:1)
您只需使用DESCRIPTION_jpeg-tools = "The jpeg-tools package includes client programs to access libjpeg functionality. These tools allow for the compression, decompression, transformation and display of JPEG files and benchmarking of the libjpeg library."
FILES_jpeg-tools = "${bindir}/*"
使您的循环“间接”。用这种方式重写你的循环:
Application.Ontime
这个想法是,不是在你的VBA例程中循环(这会阻止Excel被阻止),而是使用Sub IndirectLoop()
On Error Resume Next
Workbooks("Rapport.csv").Activate
If Err.Number = 0 Then Exit Sub ' Done!
If MsgBox("[Rapport.csv] - Workbook is currently not open." & vbNewLine & _
"Please download and open [Rapports.csv] and press OK", _
vbOKCancel, "Workbook not open") = vbCancel Then _
Exit Sub ' loop cancelled by user
' Pause VBA and reschedule the routine for 3 seconds later
' Control passes here from VBA to excel to open the file by the user'
Application.OnTime Now + TimeSerial(0, 0, 3), "IndirectLoop"
End Sub
重新安排例程。这种技术将控制从VBA传递到Excel一段时间(比如上面代码中的3秒),允许它做一些活动,即打开你正在等待的文件。