Skip to main content
added 43 characters in body
Source Link
A.S.H
  • 29.4k
  • 6
  • 25
  • 50

All you need is to make your loop "indirect", using Application.Ontime. Rewrite you loop this way:

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 ' Cancelledloop cancelled by user ' YieldPause 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 

The idea is, instead of looping within your VBA routine (which keeps Excel blocked), reschedule the routine using Application.Ontime. This technique will pass the control from VBA to Excel for some moment (say 3 seconds in the code above), permitting it to do some activity, that is open the file you're waiting for.

All you need is to make your loop "indirect", using Application.Ontime. Rewrite you loop this way:

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 ' Cancelled ' Yield 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 

The idea is, instead of looping within your VBA routine (which keeps Excel blocked), reschedule the routine using Application.Ontime. This technique will pass the control from VBA to Excel for some moment (say 3 seconds in the code above), permitting it to do some activity, that is open the file you're waiting for.

All you need is to make your loop "indirect", using Application.Ontime. Rewrite you loop this way:

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 

The idea is, instead of looping within your VBA routine (which keeps Excel blocked), reschedule the routine using Application.Ontime. This technique will pass the control from VBA to Excel for some moment (say 3 seconds in the code above), permitting it to do some activity, that is open the file you're waiting for.

added 80 characters in body
Source Link
A.S.H
  • 29.4k
  • 6
  • 25
  • 50

All you need is to make your loop "indirect", using Application.Ontime. Rewrite you loop this way:

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 ' Cancelled ' Yield 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 

The idea is, instead of looping within your VBA routine (which keeps Excel blocked), reschedule the routine using Application.Ontime`Application.Ontime. This technique will pass the control from VBA to Excel for some moment (say 3 seconds in the code above), permitting it to do some activity, that is open the file you're waiting for.

All you need is to make your loop "indirect", using Application.Ontime. Rewrite you loop this way:

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 ' Cancelled ' Yield VBA and reschedule the routine for 3 seconds later Application.OnTime Now + TimeSerial(0, 0, 3), "IndirectLoop" End Sub 

The idea is, instead of looping within your VBA routine (which keeps Excel blocked), reschedule the routine using Application.Ontime`. This technique will pass the control from VBA to Excel for some moment (say 3 seconds in the code above), permitting it to do some activity, that is open the file you're waiting for.

All you need is to make your loop "indirect", using Application.Ontime. Rewrite you loop this way:

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 ' Cancelled ' Yield 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 

The idea is, instead of looping within your VBA routine (which keeps Excel blocked), reschedule the routine using Application.Ontime. This technique will pass the control from VBA to Excel for some moment (say 3 seconds in the code above), permitting it to do some activity, that is open the file you're waiting for.

Source Link
A.S.H
  • 29.4k
  • 6
  • 25
  • 50

All you need is to make your loop "indirect", using Application.Ontime. Rewrite you loop this way:

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 ' Cancelled ' Yield VBA and reschedule the routine for 3 seconds later Application.OnTime Now + TimeSerial(0, 0, 3), "IndirectLoop" End Sub 

The idea is, instead of looping within your VBA routine (which keeps Excel blocked), reschedule the routine using Application.Ontime`. This technique will pass the control from VBA to Excel for some moment (say 3 seconds in the code above), permitting it to do some activity, that is open the file you're waiting for.